当我开发这个VS代码扩展,我不得不把光标移动到一条线,我创建vscode.window.activeTextEditor.edit的方法,但后来我意识到,当我试图将光标移动行不存在,所以我不得不把一setTimeout对尝试移动光标:
let editor: TextEditor = vscode.window.activeTextEditor;
let selections: Selection[] = editor.selections;
let doc: TextDocument = editor.document;
editor.edit(function (edit: TextEditorEdit): void {
selections.forEach((selection: Selection, index: number) => {
for (let i = selection.start.line; i <= selection.end.line; i++) {
let selLine: TextLine = doc.lineAt(i);
let insertPos: Range = selLine.range;
let insertLineText: string = selLine.text;
// This is async :(
edit.replace(insertPos, insertSemicolon(insertLineText, newLine));
}
});
if (newLine) {
// Move cursor to the next line
setTimeout(() => …Run Code Online (Sandbox Code Playgroud) 例如,在 Github 上,我们可以在提交中放置摘要消息,但我们也可以放置描述消息,因此当协作者想要查看提交的描述时,他可以了解更多详细信息:
在 TortoiseGit 中提交消息时我们该怎么做,因为他只给你 1 个输入来编写你的消息?