Skip to content

Commit ceedc38

Browse files
committed
feat: enhance log insertion by moving cursor to line end after insertion
1 parent 3488b61 commit ceedc38

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/commands/insert-log.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { window } from 'vscode'
1+
import type { TextEditor } from 'vscode'
2+
import { Position, Selection, window } from 'vscode'
23
import { buildLogStatement } from '../log'
34

45
export function insertLog() {
@@ -15,7 +16,24 @@ export function insertLog() {
1516
const logStatement = buildLogStatement(text, insertLineNumber)
1617

1718
const insertPosition = currentLine.range.end
18-
editor.edit((editBuilder) => {
19-
editBuilder.insert(insertPosition, `\n${indentation}${logStatement}`)
20-
})
19+
const fullLogStatement = `\n${indentation}${logStatement}`
20+
21+
editor
22+
.edit((editBuilder) => {
23+
editBuilder.insert(insertPosition, fullLogStatement)
24+
})
25+
.then((success) => {
26+
if (success) {
27+
moveCursorToLineEnd(editor, selection.end.line + 1)
28+
}
29+
})
30+
}
31+
32+
function moveCursorToLineEnd(editor: TextEditor, line: number) {
33+
if (line >= editor.document.lineCount)
34+
return
35+
36+
const lineText = editor.document.lineAt(line).text
37+
const newPosition = new Position(line, lineText.length)
38+
editor.selection = new Selection(newPosition, newPosition)
2139
}

0 commit comments

Comments
 (0)