correctly handling dynamic palceholders when autocompleting. see #553
This commit is contained in:
parent
c9b0e39433
commit
de7a2ca831
1 changed files with 3 additions and 2 deletions
|
|
@ -34,7 +34,7 @@ export function textareaAutocomplete(textarea, suggestions, type_value = -1) {
|
|||
type = tr.querySelector('.type_output').value
|
||||
}
|
||||
// console.log(">>>>>>>>> type: " + type);
|
||||
// console.log(">>>>>>>>> suggestions: " + JSON.stringify(suggestions));
|
||||
// console.log(">>>>>>>>> suggestions: " + JSON.stringify(suggestions));
|
||||
// console.log(">>>>>>>>> lastWord: " + lastWord);
|
||||
const matches = suggestions.filter(s => s.command.startsWith(lastWord) && (String(s.type) == String(type) || String(s.type) == '0' )).map(s => s.command);
|
||||
// console.log(">>>>>>>>> matches: " + JSON.stringify(matches));
|
||||
|
|
@ -106,6 +106,7 @@ export function textareaAutocomplete(textarea, suggestions, type_value = -1) {
|
|||
}
|
||||
|
||||
function insertAutocomplete(suggestion, textarea) {
|
||||
// console.log(">>>>>>>>> insertAutocomplete suggestion: " + JSON.stringify(suggestion));
|
||||
const cursorPosition = textarea.selectionStart;
|
||||
const textBefore = textarea.value.substring(0, cursorPosition);
|
||||
const textAfter = textarea.value.substring(cursorPosition);
|
||||
|
|
@ -115,7 +116,7 @@ export function textareaAutocomplete(textarea, suggestions, type_value = -1) {
|
|||
const completion = suggestion.substring(lastWord.length);
|
||||
const newText = textBefore + completion + textAfter;
|
||||
textarea.value = newText;
|
||||
const newCursorPosition = cursorPosition + completion.length;
|
||||
const newCursorPosition = cursorPosition + completion.length - (suggestion.endsWith(':%}') ? 2 : 0);
|
||||
textarea.setSelectionRange(newCursorPosition, newCursorPosition);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue