aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-05-10 17:34:58 +0100
committerStephen Blott2015-05-10 17:34:58 +0100
commite65f30aeebab3a6646d9918db36af325e83e0e34 (patch)
tree5b6bd076bc3a1ce835caaf7bcaaee0263b013ea9
parent91da4285f4d89f9ec43f5f8a05eaa741899d24ee (diff)
downloadvimium-e65f30aeebab3a6646d9918db36af325e83e0e34.tar.bz2
Search completion; fix for multiple spaces in input.
-rw-r--r--pages/vomnibar.coffee34
1 files changed, 16 insertions, 18 deletions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 74963bfe..e5b66574 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -99,25 +99,23 @@ class VomnibarUI
selectionEnd: @input.selectionEnd
@input.value = @completions[@selection].insertText + (if @selection == 0 then "" else " ")
else if @previousInputValue?
- @input.value = @previousInputValue.value
- if @previousInputValue.selectionStart? and @previousInputValue.selectionEnd? and
- @previousInputValue.selectionStart != @previousInputValue.selectionEnd
- @input.setSelectionRange @previousInputValue.selectionStart, @previousInputValue.selectionEnd
- @previousInputValue = null
-
- # Highlight the the selected entry, and only the selected entry.
- @highlightTheSelectedEntry()
+ # Restore the text.
+ @input.value = @previousInputValue.value
+ # Restore the selection.
+ if @previousInputValue.selectionStart? and @previousInputValue.selectionEnd? and
+ @previousInputValue.selectionStart != @previousInputValue.selectionEnd
+ @input.setSelectionRange @previousInputValue.selectionStart, @previousInputValue.selectionEnd
+ @previousInputValue = null
- highlightTheSelectedEntry: ->
+ # Highlight the selected entry, and only the selected entry.
for i in [0...@completionList.children.length]
@completionList.children[i].className = (if i == @selection then "vomnibarSelected" else "")
+ # This identifies the common part of all of the (relevant) suggestions which has yet to be typed, adds that
+ # text to the input and selects it. Tab (or just Enter) can then be used to accept the new text, or the user
+ # can just continue typing.
selectCommonMatches: (response) ->
- # For custom search engines, add characters to the input which are:
- # - not in the query/input
- # - in all completions
- # and select the added text.
-
+ #
# Bail if we don't yet have the background completer's final word on the current query.
return unless response.mayCacheResults
@@ -142,8 +140,8 @@ class VomnibarUI
# Some completion engines add text at the start of the suggestion; for example, Bing takes "they might be"
# and suggests "Ana Ng They Might be Giants". In such cases, we should still be able to complete
- # "giants". So, if the query string is present in the suggestion but there is an extra prefix, we strip
- # the prefix.
+ # "giants". So, if the query string is present in the suggestion but there is extra text at the start, we
+ # strip the prefix.
suggestions =
for suggestion in suggestions
index = Math.max 0, suggestion.toLowerCase().indexOf query
@@ -177,7 +175,7 @@ class VomnibarUI
completion = suggestions[0].slice query.length, length
- # Don't complete trailing whitespace; so, strip it. Then , verify that the completion is still long
+ # Don't complete trailing whitespace; so, strip it. Then, verify that the completion is still long
# enough.
completion = completion.replace /\s+$/, ""
return unless 0 < completion.length
@@ -186,7 +184,7 @@ class VomnibarUI
completion = completion.toLowerCase() unless /[A-Z]/.test @input.value
# Insert the completion and highlight it.
- @input.value = @input.value + completion
+ @input.value = query + completion
@input.setSelectionRange query.length, query.length + completion.length
#