diff --git a/editor/src/index.js b/editor/src/index.js index 5e07399..f9740da 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -309,21 +309,37 @@ if (holder) { return true }) - $(input).on('keyup', function () { + let searchEnabled = false + + $(input).on('keyup', function (event) { + if (event.key === '/') { + searchEnabled = true + } + if (searchEnabled && event.key === 'Escape') { + searchEnabled = false + } + let value = input.value let end = input.selectionEnd let [start, insideLink] = util.cursorInsideLink(value, end) let insideSearch = false - if (!insideLink) { + if (searchEnabled && !insideLink) { start = value.lastIndexOf("/", end) insideSearch = start >= 0 } if (insideSearch) { let query = value.substring(start + 1, end); - showSearchResults(query => commandSearch.search(query), query, input, value, 'command'); + let searchTool = query => { + let result = commandSearch.search(query); + if (query.length > 0 && result.length === 0) { + searchEnabled = false + } + return result + } + showSearchResults(searchTool, query, input, value, 'command'); return true } else if (insideLink) { let query = value.substring(start + 2, end);