Skip to content

Commit

Permalink
add autocomplete feature
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Sh4rk committed Sep 22, 2024
1 parent e4bb8d4 commit a9a0dd4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions html/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ document.addEventListener('DOMContentLoaded', () => {
}

const textBeforeWord = currentValue.substring(0, startIndex);
const textAfterWord = currentValue.substring(startIndex);
const textAfterWord = currentValue.substring(endIndex);

const pre = document.createTextNode(textBeforeWord);
const post = document.createTextNode(textAfterWord);
const post = document.createTextNode(textAfterWord + (textAfterWord.endsWith("\n") ? " " : ""));
const caretEle = document.createElement('span');
caretEle.innerHTML = ' ';
caretEle.innerHTML = '';
caretEle.append(document.createTextNode(currentWord));

mirroredEle.innerHTML = '';
mirroredEle.append(pre, caretEle, post);
mirroredEle.scrollTop = textarea.scrollTop;

const rect = caretEle.getBoundingClientRect();
suggestionsEle.style.top = `${rect.top + rect.height}px`;
Expand Down

0 comments on commit a9a0dd4

Please sign in to comment.