import * as vscode from 'vscode' ; export function left ( position , count = 1 ) { return position . with ( { character : Math . max ( position . character - count , 0 ) , } ) ; } export function right ( document , position , count = 1 ) { const lineLength = document . lineAt ( position . line ) . text . length ; return position . with ( { character : Math . min ( position . character + count , lineLength ) , } ) ; } export function rightNormal ( document , position , count = 1 ) { const lineLength = document . lineAt ( position . line ) . text . length ; if ( lineLength === 0 ) { return position . with ( { character : 0 } ) ; } else { return position . with ( { character : Math . min ( position . character + count , lineLength - 1 ) , } ) ; } } export function leftWrap ( document , position ) { if ( position . character <= 0 ) { if ( position . line <= 0 ) { return position ; } else { const previousLineLength = document . lineAt ( position . line - 1 ) . text . length ; return new vscode . Position ( position . line - 1 , previousLineLength ) ; } } else { return position . with ( { character : position . character - 1 } ) ; } } export function rightWrap ( document , position ) { const lineLength = document . lineAt ( position . line ) . text . length ; if ( position . character >= lineLength ) { if ( position . line >= document . lineCount - 1 ) { return position ; } else { return new vscode . Position ( position . line + 1 , 0 ) ; } } else { return position . with ( { character : position . character + 1 } ) ; } } export function lineEnd ( document , position ) { const lineLength = document . lineAt ( position . line ) . text . length ; return position . with ( { character : lineLength , } ) ; }