From 332eaaa85291c9b9c5fa0cf26f44ff5edf1a7c05 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 12:48:08 +0000 Subject: Give find mode a history. --- content_scripts/vimium_frontend.coffee | 46 ++++++++++++++++++++++++++++++---- lib/keyboard_utils.coffee | 2 +- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 725d8a53..b77e5606 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -48,7 +48,7 @@ settings = values: {} loadedValues: 0 valuesToLoad: ["scrollStepSize", "linkHintCharacters", "linkHintNumbers", "filterLinkHints", "hideHud", - "previousPatterns", "nextPatterns", "findModeRawQuery", "regexFindMode", "userDefinedLinkHintCss", + "previousPatterns", "nextPatterns", "findModeRawQuery", "findModeRawQueryList", "regexFindMode", "userDefinedLinkHintCss", "helpDialog_showAdvancedCommands", "smoothScroll"] isLoaded: false eventListeners: {} @@ -663,6 +663,28 @@ exitInsertMode = (target) -> isInsertMode = -> return false # Disabled. +# This implements a find-mode query history (using the "findModeRawQueryList" setting) as a list of raw +# queries, most recent first. +FindModeHistory = + getQuery: (index = 0) -> + @migration() + recentQueries = settings.get "findModeRawQueryList" + if index < recentQueries.length then recentQueries[index] else "" + + recordQuery: (query) -> + @migration() + recentQueries = settings.get "findModeRawQueryList" + if 0 < query?.length + settings.set "findModeRawQueryList", ([ query ].concat recentQueries.filter (q) -> q != query)[0..50] + + # Migration (from 1.49, 2015/2/1). + # Legacy setting: findModeRawQuery (a string). + # New setting: findModeRawQueryList (a list of strings). + migration: -> + unless settings.get "findModeRawQueryList" + rawQuery = settings.get "findModeRawQuery" + settings.set "findModeRawQueryList", (if rawQuery then [ rawQuery ] else []) + # should be called whenever rawQuery is modified. updateFindModeQuery = -> # the query can be treated differently (e.g. as a plain string versus regex depending on the presence of @@ -714,12 +736,15 @@ updateFindModeQuery = -> text = document.body.innerText findModeQuery.matchCount = text.match(pattern)?.length -handleKeyCharForFindMode = (keyChar) -> - findModeQuery.rawQuery += keyChar +updateQueryForFindMode = (rawQuery) -> + findModeQuery.rawQuery = rawQuery updateFindModeQuery() performFindInPlace() showFindModeHUDForQuery() +handleKeyCharForFindMode = (keyChar) -> + updateQueryForFindMode findModeQuery.rawQuery + keyChar + handleEscapeForFindMode = -> exitFindMode() document.body.classList.remove("vimiumFindMode") @@ -749,10 +774,11 @@ handleEnterForFindMode = -> exitFindMode() focusFoundLink() document.body.classList.add("vimiumFindMode") - settings.set("findModeRawQuery", findModeQuery.rawQuery) + FindModeHistory.recordQuery findModeQuery.rawQuery class FindMode extends Mode constructor: -> + @historyIndex = -1 super name: "find" badge: "/" @@ -767,6 +793,16 @@ class FindMode extends Mode handleEnterForFindMode() @exit() @suppressEvent + else if event.keyCode == keyCodes.upArrow + if rawQuery = FindModeHistory.getQuery @historyIndex + 1 + @historyIndex += 1 + updateQueryForFindMode rawQuery + @suppressEvent + else if event.keyCode == keyCodes.downArrow + @historyIndex = Math.max -1, @historyIndex - 1 + rawQuery = if 0 <= @historyIndex then FindModeHistory.getQuery @historyIndex else "" + updateQueryForFindMode rawQuery + @suppressEvent else DomUtils.suppressPropagation(event) handlerStack.stopBubblingAndFalse @@ -852,7 +888,7 @@ getNextQueryFromRegexMatches = (stepSize) -> findAndFocus = (backwards) -> # check if the query has been changed by a script in another frame - mostRecentQuery = settings.get("findModeRawQuery") || "" + mostRecentQuery = FindModeHistory.getQuery() if (mostRecentQuery != findModeQuery.rawQuery) findModeQuery.rawQuery = mostRecentQuery updateFindModeQuery() diff --git a/lib/keyboard_utils.coffee b/lib/keyboard_utils.coffee index 30d99656..693c9b1c 100644 --- a/lib/keyboard_utils.coffee +++ b/lib/keyboard_utils.coffee @@ -1,7 +1,7 @@ KeyboardUtils = keyCodes: { ESC: 27, backspace: 8, deleteKey: 46, enter: 13, space: 32, shiftKey: 16, ctrlKey: 17, f1: 112, - f12: 123, tab: 9 } + f12: 123, tab: 9, downArrow: 40, upArrow: 38 } keyNames: { 37: "left", 38: "up", 39: "right", 40: "down" } -- cgit v1.2.3 From 4d4bdb65d3f5b1e09fe8a55593bc57215da9a4e5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 14:20:01 +0000 Subject: Find-mode history, tweaks. --- content_scripts/vimium_frontend.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b77e5606..b76f2663 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -673,8 +673,8 @@ FindModeHistory = recordQuery: (query) -> @migration() - recentQueries = settings.get "findModeRawQueryList" - if 0 < query?.length + if 0 < query.length + recentQueries = settings.get "findModeRawQueryList" settings.set "findModeRawQueryList", ([ query ].concat recentQueries.filter (q) -> q != query)[0..50] # Migration (from 1.49, 2015/2/1). -- cgit v1.2.3 From fa9dcbab7eba2cace43ec6e31475e5d8ee5de9a0 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 15:36:15 +0000 Subject: Find mode: report "1 Match", not "1 Matches". --- content_scripts/vimium_frontend.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b76f2663..f9a73f3e 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -1015,7 +1015,8 @@ window.goNext = -> showFindModeHUDForQuery = -> if (findModeQueryHasResults || findModeQuery.parsedQuery.length == 0) - HUD.show("/" + findModeQuery.rawQuery + " (" + findModeQuery.matchCount + " Matches)") + plural = if findModeQuery.matchCount == 1 then "" else "es" + HUD.show("/" + findModeQuery.rawQuery + " (" + findModeQuery.matchCount + " Match#{plural})") else HUD.show("/" + findModeQuery.rawQuery + " (No Matches)") -- cgit v1.2.3 From 7a5ace59bdc70b9fdbe9427e86319f275116925f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 15:56:13 +0000 Subject: Do not show match count if there is no query. --- content_scripts/vimium_frontend.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f9a73f3e..b6728ce9 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -1014,11 +1014,13 @@ window.goNext = -> findAndFollowRel("next") || findAndFollowLink(nextStrings) showFindModeHUDForQuery = -> - if (findModeQueryHasResults || findModeQuery.parsedQuery.length == 0) + 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 + else if findModeQuery.rawQuery HUD.show("/" + findModeQuery.rawQuery + " (No Matches)") + else + HUD.show("/") getCurrentRange = -> selection = getSelection() -- cgit v1.2.3 From 90444bebf9478408c8332a898e7c404d0a62841f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 16:05:24 +0000 Subject: With find mode history, remember any partial query. --- content_scripts/vimium_frontend.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b6728ce9..2dcd3d9b 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -779,6 +779,7 @@ handleEnterForFindMode = -> class FindMode extends Mode constructor: -> @historyIndex = -1 + @partialQuery = "" super name: "find" badge: "/" @@ -796,11 +797,12 @@ class FindMode extends Mode else if event.keyCode == keyCodes.upArrow if rawQuery = FindModeHistory.getQuery @historyIndex + 1 @historyIndex += 1 + @partialQuery = findModeQuery.rawQuery if @historyIndex == 0 updateQueryForFindMode rawQuery @suppressEvent else if event.keyCode == keyCodes.downArrow @historyIndex = Math.max -1, @historyIndex - 1 - rawQuery = if 0 <= @historyIndex then FindModeHistory.getQuery @historyIndex else "" + rawQuery = if 0 <= @historyIndex then FindModeHistory.getQuery @historyIndex else @partialQuery updateQueryForFindMode rawQuery @suppressEvent else -- cgit v1.2.3 From bf20ceb6e804e28187dbf900904662d3b5909cdc Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 1 Feb 2015 16:20:28 +0000 Subject: Refactor (simplify) find mode. --- content_scripts/vimium_frontend.coffee | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2dcd3d9b..ce8ad1ae 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -762,10 +762,7 @@ handleDeleteForFindMode = -> exitFindMode() performFindInPlace() else - findModeQuery.rawQuery = findModeQuery.rawQuery.substring(0, findModeQuery.rawQuery.length - 1) - updateFindModeQuery() - performFindInPlace() - showFindModeHUDForQuery() + updateQueryForFindMode findModeQuery.rawQuery.substring(0, findModeQuery.rawQuery.length - 1) # sends us into insert mode if possible, but does not. # corresponds approximately to 'nevermind, I have found it already' while means 'I want to save -- cgit v1.2.3 From b082b11942dac88cff4ddb22ae0bc4426cf98bf5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 2 Feb 2015 05:33:24 +0000 Subject: Get the right match count for find. --- content_scripts/vimium_frontend.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index ce8ad1ae..e1c703e6 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -711,6 +711,9 @@ 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 -- cgit v1.2.3