【问题标题】:Found someVSCode: How can I determine the cursor's column position within an editor?找到了一些VSCode:如何确定光标在编辑器中的列位置?
【发布时间】:2021-02-23 17:52:31
【问题描述】:

我正在寻找一种简单的方法来确定 VSCode 编辑器的文本插入光标/插入符号的列位置,无论是在选择要复制的文本区域之前还是立即使用鼠标开始选择。在执行进一步的剪贴板操作之前,列号将存储在剪贴板中。

我已尝试搜索 AutoHotkey 方法来实现此目的,但我能找到的唯一解决方案是使用 ImageSearch,这不适合我的目的。

编辑:我找到了这个API reference,我是否可以使用它来确定光标位置,最好使用 windows cmd/powershell?

【问题讨论】:

    标签: visual-studio-code autohotkey vscode-extensions vscode-tasks


    【解决方案1】:

    您可以制作一个 vscode 扩展并将命令绑​​定到键盘快捷键。

    如何获取光标的行列(字符):

    const activeEditor = vscode.window.activeTextEditor
        if (activeEditor) {
            console.log(activeEditor.selection.active.line)
            console.log(activeEditor.selection.active.character) //column
        }
    

    api:https://code.visualstudio.com/api/references/vscode-api#details-159

    activeEditor.selection 为您提供一个包含 4 个对象的对象

    start:Object
      line:4
      character:8
    end:Object
      line:6
      character:8
    active:Object
      line:4
      character:8
    anchor:Object
      line:6
      character:8
    

    activeEditor.selection.active 是你的光标。

    activeEditor.selection.anchor 是

    选择开始的位置。此位置可能在活动之前或之后。

    anchor-active 可以颠倒,但 start-end 始终是 up-down。

    注意:在我发现如何从这里获取当前行之后,我找到了 api: VScode API why can't I get the current line?

    【讨论】:

      猜你喜欢
      • 2011-01-13
      • 2016-01-28
      • 1970-01-01
      • 2023-03-13
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多