From 0849300fbe2a60a91b4c270d6b217b11d5d04ac8 Mon Sep 17 00:00:00 2001 From: Timur <35872220+bornova@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:53:23 +0000 Subject: [PATCH] Improved autocomplete hints --- src/js/editor.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/js/editor.js b/src/js/editor.js index 0f22698..d4b2efa 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -147,16 +147,9 @@ Object.getOwnPropertyNames(math).forEach((f) => { }) Object.keys(formulajs).forEach((f) => { - numaraHints.push({ text: f, className: 'cm-excel' }) + numaraHints.push({ text: 'xls.' + f, className: 'cm-excel' }) }) -CodeMirror.commands.autocomplete = (cm) => { - CodeMirror.showHint(cm, CodeMirror.hint.numaraHints, { - completeSingle: false, - extraKeys: { Enter: 'newline' } - }) -} - CodeMirror.registerHelper('hint', 'numaraHints', (editor) => { const cmCursor = editor.getCursor() const cmCursorLine = editor.getLine(cmCursor.line) @@ -164,17 +157,21 @@ CodeMirror.registerHelper('hint', 'numaraHints', (editor) => { let start = cmCursor.ch let end = start - while (end < cmCursorLine.length && /[\w$]/.test(cmCursorLine.charAt(end))) { + while (end < cmCursorLine.length && /[\w.$]/.test(cmCursorLine.charAt(end))) { ++end } - while (start && /[\w$]/.test(cmCursorLine.charAt(start - 1))) { + while (start && /[\w.$]/.test(cmCursorLine.charAt(start - 1))) { --start } - const curWord = start !== end && cmCursorLine.slice(start, end) + let curStr = cmCursorLine.slice(start, end) + let curWord = start !== end && curStr + const curWordRegex = new RegExp('^' + curWord, 'i') + curWord = !curStr.endsWith('.') || curStr === 'xls.' + return { list: !curWord ? [] @@ -184,6 +181,13 @@ CodeMirror.registerHelper('hint', 'numaraHints', (editor) => { } }) +CodeMirror.commands.autocomplete = (cm) => { + CodeMirror.showHint(cm, CodeMirror.hint.numaraHints, { + completeSingle: false, + extraKeys: { Enter: 'newline', Tab: () => {} } + }) +} + // Codemirror handlers cm.on('changes', calculate)