Disable search on Escape or when no results
This commit is contained in:
parent
15be555529
commit
1637cc2056
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user