File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 1- import { window } from 'vscode'
1+ import type { TextEditor } from 'vscode'
2+ import { Position , Selection , window } from 'vscode'
23import { buildLogStatement } from '../log'
34
45export 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}
You can’t perform that action at this time.
0 commit comments