gpt4 book ai didi

visual-studio-code - 保持屏幕位置始终以光标为中心

转载 作者:行者123 更新时间:2023-12-04 16:42:29 26 4
gpt4 key购买 nike

我正在尝试为 VSCode 编写一个扩展,其中编辑器屏幕始终以光标为中心。还有其他扩展程序添加了一个命令以将屏幕居中放置在光标上,但您必须按该命令才能激活它。

目前我发现实现它的唯一方法是重写 cursorUp、cursorDown、enter、pageUp、pageDown——基本上上下移动光标的任何命令,然后使用“revealLine”命令和光标行位置和“在”属性作为“中心”。

有没有更好的方法?重新实现默认的编辑器命令似乎非常低效。

这是我目前得到的:

"use strict";
import * as vscode from "vscode";

export function activate(context: vscode.ExtensionContext) {
let disposable1 = vscode.commands.registerCommand("cursorUp",() => {
centralizar();
vscode.commands.executeCommand("cursorMove", {
to: "up",
});
}
);

let disposable2 = vscode.commands.registerCommand("cursorDown",() => {
centralizar();
vscode.commands.executeCommand("cursorMove", {
to: "down",
});
}
);

context.subscriptions.push(disposable1);
context.subscriptions.push(disposable2);
}

function centralizar() {
let currentLineNumber = vscode.window.activeTextEditor.selection.start.line;
vscode.commands.executeCommand("revealLine", {
lineNumber: currentLineNumber,
at: "center"
});
}

export function deactivate() {}

最佳答案

也许您可以使用新的 (v1.38) 命令 editor.cursorSurroundingLines。参见 scrollOff release notes .

scrollOff demo

它需要一个数字,但如果您可以获得编辑器窗口中可见行的数量,则将 editor.cursorSurroundingLines 设置为可能有效的适当中点。看来您不必监听滚动事件。但如果调整编辑器窗口的大小,则必须更新该值。

关于visual-studio-code - 保持屏幕位置始终以光标为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57330004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com