From db256c91ccd4af7b3556bac215d556bebfa9c895 Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Tue, 16 May 2017 22:54:17 -0500 Subject: [PATCH] Only autocomplete on single match --- webui/assets/main.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/webui/assets/main.js b/webui/assets/main.js index 887181338..3969ed650 100644 --- a/webui/assets/main.js +++ b/webui/assets/main.js @@ -85,20 +85,27 @@ class REPL { } var input_word = repl.input.value.substring(word_start, repl.input.selectionEnd) - // check for keyword match and insert - // this just stops at the first match + // check for keyword match and insert if exactly one match + var matches = [] for(var keyword in keywords) { if(keyword.startsWith(input_word)){ - var cursor_pos = repl.input.selectionEnd - var completion = keyword.substring(input_word.length) - var before = repl.input.value.substring(0, cursor_pos) - var after = repl.input.value.substring(cursor_pos) - repl.input.value = before + completion + after - var new_pos = cursor_pos + completion.length - keywords[keyword] - repl.input.setSelectionRange(new_pos, new_pos) - break + matches.push(keyword) } } + if(matches.length > 1) { + // display in some dynamic element + } + + if(matches.length == 1) { + var cursor_pos = repl.input.selectionEnd + var completion = matches[0].substring(input_word.length) + var before = repl.input.value.substring(0, cursor_pos) + var after = repl.input.value.substring(cursor_pos) + repl.input.value = before + completion + after + var new_pos = cursor_pos + completion.length - keywords[matches[0]] + repl.input.setSelectionRange(new_pos, new_pos) + } + } }) repl.button.onclick = function() {