diff options
| author | Stephen Blott | 2015-01-07 09:57:03 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-07 09:57:03 +0000 |
| commit | 04ac4c64c9634d9f81035ff7e9db537f39b42f3c (patch) | |
| tree | c61e1d5893916b0d3fa191e2aaf285ff7ae9629c /content_scripts/mode.coffee | |
| parent | a7fcfd9a663e2d81a86e5e49e54162399ccb5e6b (diff) | |
| download | vimium-04ac4c64c9634d9f81035ff7e9db537f39b42f3c.tar.bz2 | |
Modes; rework Singletons, InsertModeBlocker and HandlerStack.
This begins work on addressing @philc's comments in #1413. That work is
nevertheless not yet complete.
Diffstat (limited to 'content_scripts/mode.coffee')
| -rw-r--r-- | content_scripts/mode.coffee | 12 |
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 |
