Skip to content

Commit 8d95287

Browse files
authored
Merge pull request #368 from codefori/feature/fixed_format_jump
Add navigation commands for fixed-format areas in RPGLE
2 parents 9ab5348 + 4b29ef2 commit 8d95287

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

extension/client/src/language/columnAssist.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { commands, DecorationOptions, ExtensionContext, Range, ThemeColor, window } from 'vscode';
2+
import { commands, DecorationOptions, ExtensionContext, Range, Selection, TextDocument, ThemeColor, window } from 'vscode';
33
import * as Configuration from "../configuration";
44
import { 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+
4554
export 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+
95141
function 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

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@
8282
"category": "RPGLE",
8383
"enablement": "code-for-ibmi:connected",
8484
"icon": "$(refresh)"
85+
},
86+
{
87+
"command": "vscode-rpgle.assist.moveLeft",
88+
"title": "Move Left",
89+
"category": "RPGLE Fixed-Format",
90+
"icon": "$(arrow-left)",
91+
"when": "editorLangId == rpgle"
92+
},
93+
{
94+
"command": "vscode-rpgle.assist.moveRight",
95+
"title": "Move Right",
96+
"category": "RPGLE Fixed-Format",
97+
"icon": "$(arrow-right)",
98+
"when": "editorLangId == rpgle"
8599
}
86100
],
87101
"keybindings": [
@@ -96,6 +110,18 @@
96110
"key": "shift+f4",
97111
"mac": "shift+f4",
98112
"when": "editorLangId == rpgle"
113+
},
114+
{
115+
"command": "vscode-rpgle.assist.moveLeft",
116+
"key": "ctrl+[",
117+
"mac": "ctrl+[",
118+
"when": "editorLangId == rpgle"
119+
},
120+
{
121+
"command": "vscode-rpgle.assist.moveRight",
122+
"key": "ctrl+]",
123+
"mac": "ctrl+]",
124+
"when": "editorLangId == rpgle"
99125
}
100126
],
101127
"menus": {

0 commit comments

Comments
 (0)