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, {})