11
2- import { commands , DecorationOptions , ExtensionContext , Range , ThemeColor , window } from 'vscode' ;
2+ import { commands , DecorationOptions , ExtensionContext , Range , Selection , TextDocument , ThemeColor , window } from 'vscode' ;
33import * as Configuration from "../configuration" ;
44import { loadBase } from '../base' ;
55
@@ -42,6 +42,15 @@ const getAreasForLine = (line: string, index: number) => {
4242 }
4343}
4444
45+ function documentIsFree ( document : TextDocument ) {
46+ if ( document . languageId === `rpgle` ) {
47+ const line = document . getText ( new Range ( 0 , 0 , 0 , 6 ) ) . toUpperCase ( ) ;
48+ return line === `**FREE` ;
49+ }
50+
51+ return false ;
52+ }
53+
4554export function registerColumnAssist ( context : ExtensionContext ) {
4655 context . subscriptions . push (
4756 commands . registerCommand ( `vscode-rpgle.assist.launchUI` , async ( ) => {
@@ -50,7 +59,7 @@ export function registerColumnAssist(context: ExtensionContext) {
5059 const document = editor . document ;
5160
5261 if ( document . languageId === `rpgle` ) {
53- if ( document . getText ( new Range ( 0 , 0 , 0 , 6 ) ) . toUpperCase ( ) !== `**FREE` ) {
62+ if ( ! documentIsFree ( document ) ) {
5463 const lineNumber = editor . selection . start . line ;
5564 const positionIndex = editor . selection . start . character ;
5665
@@ -81,6 +90,13 @@ export function registerColumnAssist(context: ExtensionContext) {
8190 }
8291 } ) ,
8392
93+ commands . registerCommand ( `vscode-rpgle.assist.moveLeft` , ( ) => {
94+ moveFromPosition ( `left` ) ;
95+ } ) ,
96+ commands . registerCommand ( `vscode-rpgle.assist.moveRight` , ( ) => {
97+ moveFromPosition ( `right` ) ;
98+ } ) ,
99+
84100 window . onDidChangeTextEditorSelection ( e => {
85101 const editor = e . textEditor ;
86102 if ( rulerEnabled ) {
@@ -92,13 +108,43 @@ export function registerColumnAssist(context: ExtensionContext) {
92108 )
93109}
94110
111+ function moveFromPosition ( direction : "left" | "right" , editor = window . activeTextEditor ) {
112+ if ( editor && editor . document . languageId === `rpgle` && ! documentIsFree ( editor . document ) ) {
113+ const document = editor . document ;
114+ const lineNumber = editor . selection . start . line ;
115+ const positionIndex = editor . selection . start . character ;
116+
117+ const positionsData = getAreasForLine (
118+ document . getText ( new Range ( lineNumber , 0 , lineNumber , 100 ) ) ,
119+ positionIndex
120+ ) ;
121+
122+ if ( positionsData ) {
123+ let newIndex : number | undefined ;
124+ if ( direction === `left` ) {
125+ newIndex = positionsData . active - 1 ;
126+ } else
127+ if ( direction === `right` ) {
128+ newIndex = positionsData . active + 1 ;
129+ }
130+
131+ if ( newIndex !== undefined && newIndex >= 0 && newIndex < positionsData . specification . length ) {
132+ const box = positionsData . specification [ newIndex ] ;
133+ if ( box ) {
134+ editor . selection = new Selection ( lineNumber , box . start , lineNumber , box . start ) ;
135+ }
136+ }
137+ }
138+ }
139+ }
140+
95141function updateRuler ( editor = window . activeTextEditor ) {
96142 let clear = true ;
97143
98144 if ( editor ) {
99145 const document = editor . document ;
100146 if ( document . languageId === `rpgle` ) {
101- if ( document . getText ( new Range ( 0 , 0 , 0 , 6 ) ) . toUpperCase ( ) !== `**FREE` ) {
147+ if ( ! documentIsFree ( document ) ) {
102148 const lineNumber = editor . selection . start . line ;
103149 const positionIndex = editor . selection . start . character ;
104150
0 commit comments