aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee12
1 files changed, 12 insertions, 0 deletions
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