From 04ac4c64c9634d9f81035ff7e9db537f39b42f3c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 7 Jan 2015 09:57:03 +0000 Subject: Modes; rework Singletons, InsertModeBlocker and HandlerStack. This begins work on addressing @philc's comments in #1413. That work is nevertheless not yet complete. --- content_scripts/mode.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index ff75460f..e9a4a621 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -75,6 +75,7 @@ class Mode keyup: @keyup updateBadge: (badge) => @alwaysContinueBubbling => @chooseBadge badge + @registerSingleton options.singleton if options.singleton Mode.updateBadge() if @badge push: (handlers) -> @@ -116,6 +117,17 @@ class Mode func() mode.exit() + # Some modes are singletons: there may be at most one instance active at any one time. A mode is a + # singleton if options.singleton is truthy. The value of options.singleton should be the key which is + # required to be unique. See PostFindMode for an example. + @singletons: {} + registerSingleton: (singleton) -> + singletons = Mode.singletons + singletons[singleton].exit() if singletons[singleton] + singletons[singleton] = @ + @onExit => + delete singletons[singleton] if singletons[singleton] == @ + # A SingletonMode is a Mode of which there may be at most one instance (of @singleton) active at any one time. # New instances cancel previously-active instances on startup. class SingletonMode extends Mode -- cgit v1.2.3