Disable search on Escape or when no results

This commit is contained in:
Peter Stuifzand 2020-06-15 22:17:56 +02:00
parent 15be555529
commit 1637cc2056

View File

@ -309,21 +309,37 @@ if (holder) {
return true 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 value = input.value
let end = input.selectionEnd let end = input.selectionEnd
let [start, insideLink] = util.cursorInsideLink(value, end) let [start, insideLink] = util.cursorInsideLink(value, end)
let insideSearch = false let insideSearch = false
if (!insideLink) { if (searchEnabled && !insideLink) {
start = value.lastIndexOf("/", end) start = value.lastIndexOf("/", end)
insideSearch = start >= 0 insideSearch = start >= 0
} }
if (insideSearch) { if (insideSearch) {
let query = value.substring(start + 1, end); 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 return true
} else if (insideLink) { } else if (insideLink) {
let query = value.substring(start + 2, end); let query = value.substring(start + 2, end);