From 4c3af6556ea8b94a79f4b92a67f3af9088dec152 Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Sat, 2 Jan 2021 18:37:35 +0100 Subject: [PATCH] Made kalk_web symbol completion code cleaner --- kalk_web/src/Calculator.svelte | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kalk_web/src/Calculator.svelte b/kalk_web/src/Calculator.svelte index 27676a3..974ae52 100644 --- a/kalk_web/src/Calculator.svelte +++ b/kalk_web/src/Calculator.svelte @@ -86,39 +86,36 @@ /(?[^!-@\s_|^⌊⌋⌈⌉]+(_\d+)?)|(?[+\-/*%^!])/g, (substring, identifier, _, op) => { if (identifier) { + let newSubstring: string; switch (substring) { case "sqrt": { - substring = "√"; - offset += 3; + newSubstring = "√"; break; } case "sum": { - substring = "Σ"; - offset += 2; + newSubstring = "Σ"; break; } case "pi": { - substring = "π"; - offset += 1; + newSubstring = "π"; break; } case "gamma": { - substring = "Γ"; - offset += 4; + newSubstring = "Γ"; break; } case "floor": { - substring = "⌊⌋"; - offset += 3; + newSubstring = "⌊⌋"; break; } case "ceil": { - substring = "⌈⌉"; - offset += 3; + newSubstring = "⌈⌉"; break; } } + offset += substring.length - newSubstring.length; + return `${substring}`; }