From e84eb80dfa3d72f485cd82d6bb55eef55d1cc89c Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 10 Oct 2023 15:19:48 +0200 Subject: [PATCH] added: autocomplete of snippet --- main.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index f9c533a..5e0a7da 100644 --- a/main.js +++ b/main.js @@ -2089,7 +2089,12 @@ function currentline() return (md.value.substring(0, md.selectionStart).match(/\n/g) || []).length; } -function getrawline(index) +function currentcol() +{ + return md.selectionStart - Math.max(0, md.value.lastIndexOf("\n", md.selectionStart - 1)) - 1; +} + +function rawline(index) { return md.value.split("\n")[index]; } @@ -2218,6 +2223,28 @@ function applycolors() { line = "" + line + ""; } + + // autocomplete snippets + if (i == currentline()) + { + var raw = rawline(i); + var pos = currentcol(); + var slashpos = raw.substring(0, pos).lastIndexOf("/"); + if (slashpos > -1) + { + var spacepos = raw.substring(0, pos).lastIndexOf(" "); + if (slashpos > spacepos) + { + var snippetpart = raw.substring(slashpos); + var snippet = snippets.find(s => s.command.startsWith(snippetpart)); + if (snippet) + { + line += "" + snippet.command.substr(pos - slashpos) + ""; + } + } + } + } + resulthtml += (line || " ") + ""; return true;