From 7c32de1bbc3f3c5ca46198002d053863ffc7aee2 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 14 Jul 2020 20:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/codemirror/mode/cmd/cmd-additional.js | 14 ++++++++------ .../codemirror/mode/shell/shell-modified.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/assets/plugins/codemirror/mode/cmd/cmd-additional.js b/src/assets/plugins/codemirror/mode/cmd/cmd-additional.js index e52d5d6..a665632 100644 --- a/src/assets/plugins/codemirror/mode/cmd/cmd-additional.js +++ b/src/assets/plugins/codemirror/mode/cmd/cmd-additional.js @@ -30,19 +30,21 @@ token = editor.getTokenAt(cur); if (token.string == "") return // 关键字提示 - var hints = commonAtoms.concat(commonKeywords, commonCommands) - var localCommands = JSON.parse(localStorage['cmdCommands']).filter(x => !hints.includes(x)) - hints = hints.concat(localCommands).filter(x => x.slice(0, token.string.length) == token.string) + var hints = [], tokenstring = token.string.toUpperCase() + var localCommands = JSON.parse(localStorage['cmdCommands']) + commonAtoms.concat(commonKeywords, commonCommands, localCommands).forEach(x => { + if (x.toUpperCase().slice(0, token.string.length) == tokenstring && !hints.includes(x)) hints.push(x) + }) // 特殊变量提示 var specialVars = localStorage['specialVars'] if (specialVars) specialVars.split(',').forEach(s => { - if (s.toUpperCase().slice(2, token.string.length + 2) == token.string.toUpperCase()) hints.push(s) + if (s.toUpperCase().slice(2, token.string.length + 2) == tokenstring) hints.push(s) }) // 本地单词提示 var anyword = CodeMirror.hint.anyword(editor, options).list anyword.forEach(a => { if (!hints.includes(a)) hints.push(a) - }) + }) return { list: hints, from: CodeMirror.Pos(cur.line, token.start), @@ -171,4 +173,4 @@ // http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types CodeMirror.defineMIME('application/x-sh', 'cmd'); -}); \ No newline at end of file +}); diff --git a/src/assets/plugins/codemirror/mode/shell/shell-modified.js b/src/assets/plugins/codemirror/mode/shell/shell-modified.js index 4b6a987..17d8083 100644 --- a/src/assets/plugins/codemirror/mode/shell/shell-modified.js +++ b/src/assets/plugins/codemirror/mode/shell/shell-modified.js @@ -32,19 +32,21 @@ token = editor.getTokenAt(cur); if (token.string == "") return // 关键字提示 - var hints = commonAtoms.concat(commonKeywords, commonCommands) - var localCommands = JSON.parse(localStorage['shellCommands']).filter(x => !hints.includes(x)) - hints = hints.concat(localCommands).filter(x => x.slice(0, token.string.length) == token.string) + var hints = [], tokenstring = token.string.toUpperCase() + var localCommands = JSON.parse(localStorage['shellCommands']) + commonAtoms.concat(commonKeywords, commonCommands, localCommands).forEach(x => { + if (x.toUpperCase().slice(0, token.string.length) == tokenstring && !hints.includes(x)) hints.push(x) + }) // 特殊变量提示 var specialVars = localStorage['specialVars'] if (specialVars) specialVars.split(',').forEach(s => { - if (s.toUpperCase().slice(2, token.string.length + 2) == token.string.toUpperCase()) hints.push(s) + if (s.toUpperCase().slice(2, token.string.length + 2) == tokenstring) hints.push(s) }) // 本地单词提示 var anyword = CodeMirror.hint.anyword(editor, options).list anyword.forEach(a => { if (!hints.includes(a)) hints.push(a) - }) + }) return { list: hints, from: CodeMirror.Pos(cur.line, token.start), @@ -171,4 +173,4 @@ // http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types CodeMirror.defineMIME('application/x-sh', 'shell'); -}); \ No newline at end of file +});