From c17775323baf93e0d9bd44a6f83cd32a986b6fcb Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 10:50:48 +0000 Subject: refactor(plugin): share formatting triggers and selection boundaries Co-Authored-By: Claude Opus 5.5 --- plugin/src/indentation.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'plugin/src/indentation.js') 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 }; -- cgit v1.3.1-4-g156e