From acefe43cef5a216cb2504e85799699c359b6b4d8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 31 Dec 2014 20:52:27 +0000 Subject: Modes; incorporate three test modes. As a proof of concept, this incorporates normal mode, passkeys mode and insert mode. --- background_scripts/main.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4c1b9ae7..7d7359b8 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -339,6 +339,13 @@ updateOpenTabs = (tab) -> setBrowserActionIcon = (tabId,path) -> chrome.browserAction.setIcon({ tabId: tabId, path: path }) +# This color should match the blue of the Vimium browser popup (although it looks a little darker, to me?). +chrome.browserAction.setBadgeBackgroundColor {color: [102, 176, 226, 255]} + +setBadge = (response) -> + badge = response?.badge || "" + chrome.browserAction.setBadgeText {text: badge} + # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. # This lets you disable Vimium on a page without needing to reload. @@ -349,6 +356,7 @@ root.updateActiveState = updateActiveState = (tabId) -> partialIcon = "icons/browser_action_partial.png" chrome.tabs.get tabId, (tab) -> chrome.tabs.sendMessage tabId, { name: "getActiveState" }, (response) -> + setBadge response if response isCurrentlyEnabled = response.enabled currentPasskeys = response.passKeys @@ -602,6 +610,7 @@ unregisterFrame = (request, sender) -> frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (id) -> id != request.frameId handleFrameFocused = (request, sender) -> + setBadge request tabId = sender.tab.id if frameIdsForTab[tabId]? frameIdsForTab[tabId] = @@ -633,6 +642,7 @@ sendRequestHandlers = refreshCompleter: refreshCompleter createMark: Marks.create.bind(Marks) gotoMark: Marks.goto.bind(Marks) + setBadge: setBadge # Convenience function for development use. window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html')) -- cgit v1.2.3 From 20ebbf3de2384738af916a441470d74a5aca14a3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 2 Jan 2015 10:24:39 +0000 Subject: Modes; rework badge handling and fix passkeys mode. --- background_scripts/main.coffee | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 7d7359b8..3ce05a49 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -342,9 +342,8 @@ setBrowserActionIcon = (tabId,path) -> # This color should match the blue of the Vimium browser popup (although it looks a little darker, to me?). chrome.browserAction.setBadgeBackgroundColor {color: [102, 176, 226, 255]} -setBadge = (response) -> - badge = response?.badge || "" - chrome.browserAction.setBadgeText {text: badge} +setBadge = (request) -> + chrome.browserAction.setBadgeText {text: request.badge || ""} # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. @@ -356,7 +355,6 @@ root.updateActiveState = updateActiveState = (tabId) -> partialIcon = "icons/browser_action_partial.png" chrome.tabs.get tabId, (tab) -> chrome.tabs.sendMessage tabId, { name: "getActiveState" }, (response) -> - setBadge response if response isCurrentlyEnabled = response.enabled currentPasskeys = response.passKeys @@ -610,7 +608,6 @@ unregisterFrame = (request, sender) -> frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (id) -> id != request.frameId handleFrameFocused = (request, sender) -> - setBadge request tabId = sender.tab.id if frameIdsForTab[tabId]? frameIdsForTab[tabId] = -- cgit v1.2.3 From b179d80ac9c35eb85de3995e4c4fb7dc9945ed75 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 2 Jan 2015 13:22:31 +0000 Subject: Modes; fix badges. --- background_scripts/main.coffee | 1 + 1 file changed, 1 insertion(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 3ce05a49..fc0a792f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -373,6 +373,7 @@ root.updateActiveState = updateActiveState = (tabId) -> else # We didn't get a response from the front end, so Vimium isn't running. setBrowserActionIcon(tabId,disabledIcon) + setBadge {badge: ""} handleUpdateScrollPosition = (request, sender) -> updateScrollPosition(sender.tab, request.scrollX, request.scrollY) -- cgit v1.2.3 From b7d5e25e353010505db7754e97d4387c8aa6b8fc Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 2 Jan 2015 15:01:32 +0000 Subject: Modes; simplify badge handling. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index fc0a792f..8d36de95 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -352,7 +352,7 @@ setBadge = (request) -> root.updateActiveState = updateActiveState = (tabId) -> enabledIcon = "icons/browser_action_enabled.png" disabledIcon = "icons/browser_action_disabled.png" - partialIcon = "icons/browser_action_partial.png" + partialIcon = enabledIcon # Let's try diabling that while we're playing with badges... "icons/browser_action_partial.png" chrome.tabs.get tabId, (tab) -> chrome.tabs.sendMessage tabId, { name: "getActiveState" }, (response) -> if response -- cgit v1.2.3 From 2d8c478e8086abf80b206d0fd8abc488a035b5cd Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 2 Jan 2015 15:59:58 +0000 Subject: Modes; incorporate find mode. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 8d36de95..fc0a792f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -352,7 +352,7 @@ setBadge = (request) -> root.updateActiveState = updateActiveState = (tabId) -> enabledIcon = "icons/browser_action_enabled.png" disabledIcon = "icons/browser_action_disabled.png" - partialIcon = enabledIcon # Let's try diabling that while we're playing with badges... "icons/browser_action_partial.png" + partialIcon = "icons/browser_action_partial.png" chrome.tabs.get tabId, (tab) -> chrome.tabs.sendMessage tabId, { name: "getActiveState" }, (response) -> if response -- cgit v1.2.3 From 762b17344a1d12aa58c5df2f3eef452175dc0166 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 3 Jan 2015 16:30:32 +0000 Subject: Modes; visual-mode template. Visual mode command has been create: bound to `v`, of course. The template is in mode_visual.coffee. It shouldn't really be necessary to make changes outside of there. Let me know if you have any issues. --- background_scripts/commands.coffee | 3 +++ 1 file changed, 3 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 585ef572..407fb067 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -111,6 +111,7 @@ Commands = "goUp", "goToRoot", "enterInsertMode", + "enterVisualMode", "focusInput", "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab", @@ -195,6 +196,7 @@ defaultKeyMappings = "gs": "toggleViewSource" "i": "enterInsertMode" + "v": "enterVisualMode" "H": "goBack" "L": "goForward" @@ -283,6 +285,7 @@ commandDescriptions = openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 20 }] enterInsertMode: ["Enter insert mode", { noRepeat: true }] + enterVisualMode: ["Enter visual mode", { noRepeat: true }] focusInput: ["Focus the first text box on the page. Cycle between them using tab", { passCountToFunction: true }] -- cgit v1.2.3 From 9ae4b6c10d53153929d905f28bc7de57c0ba6dfe Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Jan 2015 09:29:36 +0000 Subject: Modes; various improvements. - Add StateMode. - PasskeysMode is a StateMode. - BadgeUpdateMode is a StateMode. - Improve badge handling. - Add push method to Mode. - Document how modes work. - Cache badge on background page to reduce the number of updates. - Remove badge restriction on document.body?.tagName.toLowerCase() == "frameset". - Add ExitOnEscape mode, use it for ConstrainedMode and FindMode. - Move PostFindMode to its own file. --- background_scripts/main.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index fc0a792f..008eb89f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -342,8 +342,13 @@ setBrowserActionIcon = (tabId,path) -> # This color should match the blue of the Vimium browser popup (although it looks a little darker, to me?). chrome.browserAction.setBadgeBackgroundColor {color: [102, 176, 226, 255]} -setBadge = (request) -> - chrome.browserAction.setBadgeText {text: request.badge || ""} +setBadge = do -> + current = "" + (request) -> + badge = request.badge + if badge? and badge != current + chrome.browserAction.setBadgeText {text: badge || ""} + current = badge # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. -- cgit v1.2.3 From d745bf63ca785e360ddc48d6ad2ed430523d461c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 6 Jan 2015 05:54:29 +0000 Subject: Modes; Note visual mode not yet implemented. --- background_scripts/commands.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 407fb067..485195a9 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -285,7 +285,7 @@ commandDescriptions = openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 20 }] enterInsertMode: ["Enter insert mode", { noRepeat: true }] - enterVisualMode: ["Enter visual mode", { noRepeat: true }] + enterVisualMode: ["Enter visual mode (not yet implemented)", { noRepeat: true }] focusInput: ["Focus the first text box on the page. Cycle between them using tab", { passCountToFunction: true }] -- cgit v1.2.3 From 2fe40dd69bb93b620da60464b9cb57c36adaeca1 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 8 Jan 2015 12:02:03 +0000 Subject: Modes; incorporate small changes from #1413. Slightly more significant: Move several utilities to dome_utils. --- background_scripts/main.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 008eb89f..e8f39326 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -340,7 +340,8 @@ setBrowserActionIcon = (tabId,path) -> chrome.browserAction.setIcon({ tabId: tabId, path: path }) # This color should match the blue of the Vimium browser popup (although it looks a little darker, to me?). -chrome.browserAction.setBadgeBackgroundColor {color: [102, 176, 226, 255]} +chrome.browserAction.setBadgeBackgroundColor + color: [102, 176, 226, 255] setBadge = do -> current = "" -- cgit v1.2.3 From cd49c88eaad6550ba768159347be6c88f1c26d15 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 16 Jan 2015 12:08:42 +0000 Subject: Modes; clean up. --- background_scripts/main.coffee | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index e8f39326..83a6b3f8 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -339,17 +339,29 @@ updateOpenTabs = (tab) -> setBrowserActionIcon = (tabId,path) -> chrome.browserAction.setIcon({ tabId: tabId, path: path }) -# This color should match the blue of the Vimium browser popup (although it looks a little darker, to me?). chrome.browserAction.setBadgeBackgroundColor - color: [102, 176, 226, 255] + # This is Vimium blue (from the icon). + # color: [102, 176, 226, 255] + # This is a slightly darker blue. It makes the badge more striking in the corner of the eye, and the symbol + # easier to read. + color: [82, 156, 206, 255] setBadge = do -> current = "" + timer = null + updateBadge = (badge) -> -> chrome.browserAction.setBadgeText text: badge (request) -> badge = request.badge if badge? and badge != current - chrome.browserAction.setBadgeText {text: badge || ""} current = badge + clearTimeout timer if timer + if badge == "" + # We set an empty badge immediately. This is the common case when changing tabs. + updateBadge(badge)() + else + # We wait a few milliseconds before setting any other badge. This avoids badge flicker when there are + # rapid changes (e.g. InsertMode is activated by find, followed almost immediately by PostFindMode). + timer = setTimeout updateBadge(badge), 50 # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. -- cgit v1.2.3 From 0e59b99e95e6a4fd3f64fd284e7417ba5f7e22e1 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 18 Jan 2015 06:27:38 +0000 Subject: Modes; pre-merge clean up. --- background_scripts/main.coffee | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 83a6b3f8..c1c8dfc8 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -347,7 +347,7 @@ chrome.browserAction.setBadgeBackgroundColor color: [82, 156, 206, 255] setBadge = do -> - current = "" + current = null timer = null updateBadge = (badge) -> -> chrome.browserAction.setBadgeText text: badge (request) -> @@ -355,13 +355,8 @@ setBadge = do -> if badge? and badge != current current = badge clearTimeout timer if timer - if badge == "" - # We set an empty badge immediately. This is the common case when changing tabs. - updateBadge(badge)() - else - # We wait a few milliseconds before setting any other badge. This avoids badge flicker when there are - # rapid changes (e.g. InsertMode is activated by find, followed almost immediately by PostFindMode). - timer = setTimeout updateBadge(badge), 50 + # We wait a few moments. This avoids badge flicker when there are rapid changes. + timer = setTimeout updateBadge(badge), 50 # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page. # Also propagates new enabled/disabled/passkeys state to active window, if necessary. -- cgit v1.2.3