Mac中Xcode、文本编辑器逆天复制 竖选文本 垂直选文本

 

https://blog.csdn.net/Mo_Mo123/article/details/52348790

可能你会遇到这种需求,我想复制每一行的某一部分内容,如下

const NSTextAlignment TTTTextAlignmentLeft = NSTextAlignmentLeft;
const NSTextAlignment TTTTextAlignmentCenter = NSTextAlignmentCenter;
const NSTextAlignment TTTTextAlignmentRight = NSTextAlignmentRight;
const NSTextAlignment TTTTextAlignmentJustified = NSTextAlignmentJustified;
const NSTextAlignment TTTTextAlignmentNatural = NSTextAlignmentNatural;

上面是我找的一段代码,假如我想复制前面一列的const NSTextAlignment,怎么办呢? 
传统方法是: 
conmand+C,command+V重复五次 
稍快一点的方法是: 
按住command,在每一行选择五次,然后进行一次conmand+C,command+V 
当然上面的两种方法对于Mac用户已经司空见惯,根本称不上逆天。

下面我就来介绍一下一个逆天的方法:

  • 首先应该是一下当前软件是否支持这种用法
  • 做法如下: 
    按住option键,如果光标变成十字选择线,说明支持,否则说明当前软件不支持。

如果支持具体做法如下: 
按下option键,待光标变成十字线后去选择,然后conmand+C,command+V 

 

 

You can save time by using multiple cursors when editing files. For example, use multiple cursors to change the parameters of common method calls or select all the types in variable declarations that appear on adjacent but separate lines.

 

To select a column of text, Option-drag across the lines.

You can enter multiple cursor mode by inserting multiple cursors, selecting a range of text across lines, or selecting multiple strings in the file.

Insert multiple cursors: Press and hold Control-Shift, click each location where you want to insert a cursor, then release Control-Shift. If you need to remove a cursor, click it before you release Control-Shift. While you are in multiple cursor mode, the cursors are all blinking.

Before you start editing, you can reposition the cursors:

  • To move the cursors left, right, up, or down, use the arrow keys.
  • To move the cursors forward or backward by word, press Option-right or Option-left.

Select a range of text across lines: Press and hold Option (pointer changes to a Plus (+)), then drag over the text you want to select. Alternatively, select multiple lines of text, then choose Editor > Selection > Split Selection By Lines. A cursor is inserted on each line at the beginning of the selection.

Before you start editing with multiple cursors, you can modify the selection:

  • To extend the selection by a line, press Control-Shift-up or Control-Shift-down.
  • To extend the selection by a word, press Option-Shift-right or Option-Shift-left.

Select multiple strings: Press and hold Control-Shift, double-click or select the strings, then release Control-Shift. To add a string, Control-Shift-double-click or Control-Shift-drag.

Cancel multiple cursor editing: Press Escape or click anywhere in the file.

For more keyboard shortcuts, go to View specific actions or keyboard shortcuts.

Was this help page useful? Send feedback.

当然!这是一个简单的示例,使用 Swift 编写一个基本的文本编辑器: ```swift import Cocoa // 创建一个自定义的文本编辑器视图控制器 class TextEditorViewController: NSViewController { private var textView: NSTextView! override func loadView() { // 创建一个基本的视图 let view = NSView() view.frame = NSRect(x: 0, y: 0, width: 800, height: 600) // 创建一个文本编辑视图 textView = NSTextView(frame: view.bounds) textView.autoresizingMask = [.width, .height] textView.isRichText = false // 将文本编辑视图添加到主视图 view.addSubview(textView) // 将主视图设置为控制器的视图 self.view = view } } // 创建一个自定义的应用程序委托类 class AppDelegate: NSObject, NSApplicationDelegate { private var window: NSWindow! func applicationDidFinishLaunching(_ notification: Notification) { // 创建应用程序主窗口 window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 800, height: 600), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false) // 创建文本编辑器视图控制器实例 let textEditorViewController = TextEditorViewController() // 设置主窗口的内容视图控制器 window.contentViewController = textEditorViewController // 显示主窗口 window.makeKeyAndOrderFront(nil) } } // 创建应用程序实例 let application = NSApplication.shared // 创建应用程序委托对象 let appDelegate = AppDelegate() // 设置应用程序委托 application.delegate = appDelegate // 运行应用程序主循环 application.run() ``` 在 Xcode 创建一个新的 Swift 项目,将以上代码复制到项目的 `main.swift` 文件。这将创建一个基本的 macOS 应用程序,其包含一个文本编辑器视图。运行该应用程序后,将显示一个窗口,你可以在其进行文本编辑。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值