aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932015-05-28 22:12:08 +0100
committermrmr19932015-06-10 17:21:22 +0100
commit85aa76ec68167ea0ac08cc627b3f12e1077b1b1f (patch)
treeef3af1d54974f902be287d882bbbb1165082d196
parentf3e62301cf51fbeea77fb49eb90f1b7b9138d118 (diff)
downloadvimium-85aa76ec68167ea0ac08cc627b3f12e1077b1b1f.tar.bz2
Decide find mode text in the HUD iframe, not in frontend
-rw-r--r--content_scripts/hud.coffee8
-rw-r--r--content_scripts/vimium_frontend.coffee17
-rw-r--r--pages/hud.coffee26
3 files changed, 40 insertions, 11 deletions
diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee
index 84b8abeb..3e749da5 100644
--- a/content_scripts/hud.coffee
+++ b/content_scripts/hud.coffee
@@ -26,6 +26,14 @@ HUD =
@hudUI.show {name: "show", text}
@tween.fade 1.0, 150
+ showFindMode: (text = "") ->
+ return unless @enabled()
+ @hudUI.show {name: "showFindMode", text}
+ @tween.fade 1.0, 150
+
+ updateMatchesCount: (matchCount, showMatchText = true) ->
+ @hudUI.postMessage {name: "updateMatchesCount", matchCount, showMatchText}
+
# Hide the HUD.
# If :immediate is falsy, then the HUD is faded out smoothly (otherwise it is hidden immediately).
# If :updateIndicator is truthy, then we also refresh the mode indicator. The only time we don't update the
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 8c28b4e6..46af3847 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -686,9 +686,6 @@ updateFindModeQuery = ->
# default to 'smartcase' mode, unless noIgnoreCase is explicitly specified
findModeQuery.ignoreCase = !hasNoIgnoreCaseFlag && !Utils.hasUpperCase(findModeQuery.parsedQuery)
- # Don't count matches in the HUD.
- HUD.hide(true)
-
# if we are dealing with a regex, grep for all matches in the text, and then call window.find() on them
# sequentially so the browser handles the scrolling / text selection.
if findModeQuery.isRegex
@@ -993,13 +990,11 @@ window.goNext = ->
findAndFollowRel("next") || findAndFollowLink(nextStrings)
showFindModeHUDForQuery = ->
- if findModeQuery.rawQuery and (findModeQueryHasResults || findModeQuery.parsedQuery.length == 0)
- plural = if findModeQuery.matchCount == 1 then "" else "es"
- HUD.show("/" + findModeQuery.rawQuery + " (" + findModeQuery.matchCount + " Match#{plural})")
- else if findModeQuery.rawQuery
- HUD.show("/" + findModeQuery.rawQuery + " (No Matches)")
- else
- HUD.show("/")
+ matchCount = if findModeQuery.parsedQuery.length > 0 then findModeQuery.matchCount else 0
+ showCount = findModeQuery.rawQuery.length > 0
+
+ HUD.showFindMode findModeQuery.rawQuery
+ HUD.updateMatchesCount matchCount, showCount
getCurrentRange = ->
selection = getSelection()
@@ -1027,7 +1022,7 @@ window.enterFindMode = (options = {}) ->
findModeSaveSelection()
findModeQuery = rawQuery: ""
findMode = new FindMode options
- HUD.show "/"
+ HUD.showFindMode()
findMode
window.showHelpDialog = (html, fid) ->
diff --git a/pages/hud.coffee b/pages/hud.coffee
index 68283451..a1eef836 100644
--- a/pages/hud.coffee
+++ b/pages/hud.coffee
@@ -10,6 +10,32 @@ handlers =
document.getElementById("hud").classList.add "vimiumUIComponentHidden"
document.getElementById("hud").classList.remove "vimiumUIComponentVisible"
+ showFindMode: (data) ->
+ hud = document.getElementById "hud"
+ hud.innerText = "/"
+
+ inputElement = document.createElement "span"
+ inputElement.innerText = data.text
+ inputElement.id = "hud-find-input"
+ hud.appendChild inputElement
+
+ updateMatchesCount: ({matchCount, showMatchText}) ->
+ inputElement = document.getElementById "hud-find-input"
+ return unless inputElement? # Don't do anything if we're not in find mode.
+ nodeAfter = inputElement.nextSibling # The node containing the old match text.
+
+ if showMatchText
+ plural = if matchCount == 1 then "" else "es"
+ countText = if matchCount > 0
+ " (" + matchCount + " Match#{plural})"
+ else
+ " (No matches)"
+
+ # Replace the old count (if there was one) with the new one.
+ document.getElementById("hud").insertBefore document.createTextNode(countText), nodeAfter
+
+ nodeAfter?.remove() # Remove the old match text.
+
UIComponentServer.registerHandler (event) ->
{data} = event
handlers[data.name]? data