aboutsummaryrefslogtreecommitdiff
path: root/plugin/src/indentation.js
diff options
context:
space:
mode:
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 };