From 2bb0c0191447721cf400c3de5bdeb62b80465f29 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 31 May 2020 22:23:28 +0200 Subject: [PATCH] Scroll into view and move back to input --- editor/src/index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/editor/src/index.js b/editor/src/index.js index d14354f..8ce6b23 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -84,7 +84,7 @@ if (holder) { const $popup = $('#link-complete') if (event.key === 'Escape') { $popup.fadeOut() - return false; + return false } if (event.key === 'Enter') { @@ -100,8 +100,13 @@ if (holder) { if (prev.length) { prev.addClass('selected') selected.removeClass('selected') + prev[0].scrollIntoView() + } else { + // move back from dropdown to input + $popup.trigger('popup:leave') + selected.removeClass('selected') } - return false; + return false } if (event.key === 'ArrowDown') { @@ -110,6 +115,7 @@ if (holder) { if (next.length) { next.addClass('selected') selected.removeClass('selected') + next[0].scrollIntoView() } return false } @@ -134,13 +140,17 @@ if (holder) { return true }) + $lc.on('popup:leave', function (event) { + input.focus() + }) + $(input).on('keydown', function (event) { const isVisible = $('#link-complete:visible').length > 0; const $lc = $('#link-complete') if (event.key === 'Escape' && isVisible) { $lc.fadeOut() - return true + return false } if (event.key === 'ArrowDown' && isVisible) { @@ -159,7 +169,7 @@ if (holder) { if (start < linkEnd) { return } - let query = value.substring(start, end); + let query = value.substring(start+2, end); let results = search.search(query) let pos = getCaretCoordinates(input, value.selectionEnd, {})