aboutsummaryrefslogtreecommitdiff
path: root/plugin/src/indentation.js
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-21 10:50:48 +0000
committer_ov4 <ov4@ov4.org>2026-10-21 10:50:48 +0000
commitc17775323baf93e0d9bd44a6f83cd32a986b6fcb (patch)
tree5042cc79afb321b445e3a5a39b36eb1c4eae08b5 /plugin/src/indentation.js
parent75c0e28e3d56878dbd492cb0c6d6bf341f9e6de7 (diff)
refactor(plugin): share formatting triggers and selection boundaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'plugin/src/indentation.js')
-rw-r--r--plugin/src/indentation.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/plugin/src/indentation.js b/plugin/src/indentation.js
index b7fca78..fd3f585 100644
--- a/plugin/src/indentation.js
+++ b/plugin/src/indentation.js
@@ -1,6 +1,15 @@
'use strict';
const { codeOnly } = require('./lexical');
+const onTypeCharacters = ['\n', 'E', 'F', 'L', 'T', 'N', 'H', 'Y'];
+
+function shouldFormatOnType(line, character) {
+ return character === '\n' || /^\s*(?:ELSE|ENDIF|ENDWHILE|UNTIL|NEXT|ENDFUNCTION|ENDPROCEDURE|ENDTYPE|CATCH|ENDTRY)\b/.test(codeOnly(line));
+}
+
+function selectionEndLine(startLine, endLine, endColumn) {
+ return endColumn === 0 && endLine > startLine ? endLine - 1 : endLine;
+}
const closers = {
ENDIF: 'IF', ENDWHILE: 'WHILE', UNTIL: 'REPEAT', NEXT: 'FOR',
ENDFUNCTION: 'FUNCTION', ENDPROCEDURE: 'PROCEDURE', ENDTYPE: 'TYPE', ENDTRY: 'TRY'
@@ -56,4 +65,4 @@ function indentationEdits(lines, startLine, endLine, keepBlankIndent = false) {
return edits;
}
-module.exports = { lineDepths, indentationEdits };
+module.exports = { lineDepths, indentationEdits, onTypeCharacters, shouldFormatOnType, selectionEndLine };