mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Close the autocomplete window once user moved outside current term
This commit is contained in:
parent
8c988b002d
commit
f31fcf86b3
1 changed files with 14 additions and 2 deletions
|
@ -71,8 +71,20 @@ function keydownHandler(event) {
|
||||||
firstItem = document.querySelector('.autocomplete__item:first-of-type'),
|
firstItem = document.querySelector('.autocomplete__item:first-of-type'),
|
||||||
lastItem = document.querySelector('.autocomplete__item:last-of-type');
|
lastItem = document.querySelector('.autocomplete__item:last-of-type');
|
||||||
|
|
||||||
|
if (isSearchField()) {
|
||||||
// Prevent submission of the search field when Enter was hit
|
// Prevent submission of the search field when Enter was hit
|
||||||
if (event.keyCode === 13 && isSearchField() && selected) event.preventDefault(); // Enter
|
if (selected && event.keyCode === 13) event.preventDefault(); // Enter
|
||||||
|
|
||||||
|
// Close autocompletion popup when text cursor is outside current tag
|
||||||
|
if (selectedTerm && firstItem && (event.keyCode === 37 || event.keyCode === 39)) { // ArrowLeft || ArrowRight
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const selectionIndex = Math.min(inputField.selectionStart, inputField.selectionEnd);
|
||||||
|
const [startIndex, endIndex] = selectedTerm[0];
|
||||||
|
|
||||||
|
if (startIndex > selectionIndex || endIndex < selectionIndex) removeParent();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.keyCode === 38) changeSelected(lastItem, selected, selected && selected.previousSibling); // ArrowUp
|
if (event.keyCode === 38) changeSelected(lastItem, selected, selected && selected.previousSibling); // ArrowUp
|
||||||
if (event.keyCode === 40) changeSelected(firstItem, selected, selected && selected.nextSibling); // ArrowDown
|
if (event.keyCode === 40) changeSelected(firstItem, selected, selected && selected.nextSibling); // ArrowDown
|
||||||
|
|
Loading…
Reference in a new issue