1
1
2
- import { commands , DecorationOptions , ExtensionContext , Range , ThemeColor , window } from 'vscode' ;
2
+ import { commands , DecorationOptions , ExtensionContext , Range , Selection , TextDocument , ThemeColor , window } from 'vscode' ;
3
3
import * as Configuration from "../configuration" ;
4
4
import { loadBase } from '../base' ;
5
5
@@ -42,6 +42,15 @@ const getAreasForLine = (line: string, index: number) => {
42
42
}
43
43
}
44
44
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
+
45
54
export function registerColumnAssist ( context : ExtensionContext ) {
46
55
context . subscriptions . push (
47
56
commands . registerCommand ( `vscode-rpgle.assist.launchUI` , async ( ) => {
@@ -50,7 +59,7 @@ export function registerColumnAssist(context: ExtensionContext) {
50
59
const document = editor . document ;
51
60
52
61
if ( document . languageId === `rpgle` ) {
53
- if ( document . getText ( new Range ( 0 , 0 , 0 , 6 ) ) . toUpperCase ( ) !== `**FREE` ) {
62
+ if ( ! documentIsFree ( document ) ) {
54
63
const lineNumber = editor . selection . start . line ;
55
64
const positionIndex = editor . selection . start . character ;
56
65
@@ -81,6 +90,13 @@ export function registerColumnAssist(context: ExtensionContext) {
81
90
}
82
91
} ) ,
83
92
93
+ commands . registerCommand ( `vscode-rpgle.assist.moveLeft` , ( ) => {
94
+ moveFromPosition ( `left` ) ;
95
+ } ) ,
96
+ commands . registerCommand ( `vscode-rpgle.assist.moveRight` , ( ) => {
97
+ moveFromPosition ( `right` ) ;
98
+ } ) ,
99
+
84
100
window . onDidChangeTextEditorSelection ( e => {
85
101
const editor = e . textEditor ;
86
102
if ( rulerEnabled ) {
@@ -92,13 +108,43 @@ export function registerColumnAssist(context: ExtensionContext) {
92
108
)
93
109
}
94
110
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
+
95
141
function updateRuler ( editor = window . activeTextEditor ) {
96
142
let clear = true ;
97
143
98
144
if ( editor ) {
99
145
const document = editor . document ;
100
146
if ( document . languageId === `rpgle` ) {
101
- if ( document . getText ( new Range ( 0 , 0 , 0 , 6 ) ) . toUpperCase ( ) !== `**FREE` ) {
147
+ if ( ! documentIsFree ( document ) ) {
102
148
const lineNumber = editor . selection . start . line ;
103
149
const positionIndex = editor . selection . start . character ;
104
150
0 commit comments