将选择范围扩大到自定义行

Expand selection to custom line

我想知道是否有开箱即用的方法,或者可以在 SublimeText3 中实现以下行为的插件。

我想将插入符放在某一行。然后 select 所有文本,直到另一个行号。行数应该是可变的。

例如,将插入符号放在 10 上,然后将 selection 扩展到第 21 行或第 104 行。

我讨厌必须按住键或使用鼠标才能执行此操作。

我写了一个简单的插件,允许你输入一行到 select 直到通过 input_panel:


特点:

  • 双向工作
  • 尊重当前的select离子
  • 仅在存在单个 selection
  • 时执行

设置信息:

@ GitHub


代码:

import sublime, sublime_plugin

class SelectToLineCommand( sublime_plugin.TextCommand ):

    def run( self, edit ):

        window     = self.view.window()
        selections = self.view.sel()

        if len( selections ) != 1:
            return

        self.currentSelection = selections[0]

        if self.currentSelection.a > self.currentSelection.b:
            self.currentSelection = sublime.Region( self.currentSelection.b, self.currentSelection.a )

        window.show_input_panel( "Select To Line Number", "", self.get_LineNumber, None, None )

    def get_LineNumber( self, userInput ):

        lineToRow_Offset = 1
        row = int( userInput ) - lineToRow_Offset
        selectionEnd_Row = self.view.text_point( row, 0 )

        currentSelection = self.currentSelection

        if selectionEnd_Row >= currentSelection.b:
            selectionStart = currentSelection.a
            selectionEnd   = self.view.line( selectionEnd_Row ).b
        elif selectionEnd_Row < currentSelection.a:
            selectionStart = currentSelection.b
            selectionEnd   = self.view.line( selectionEnd_Row ).a

        newSelection = sublime.Region( selectionStart, selectionEnd )

        self.view.selection.clear()
        self.view.selection.add( newSelection )