diff options
| author | Stephen Blott | 2015-01-28 10:32:53 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-01-28 12:03:50 +0000 | 
| commit | 786b8ba0854b71e7bee00248b3ee29da357ba8d0 (patch) | |
| tree | f0182497cbd0e72605cbfcd418d6964dc2277d44 /content_scripts/mode.coffee | |
| parent | c117ac90faf8c685b40195ac54b237dfcb2b648b (diff) | |
| download | vimium-786b8ba0854b71e7bee00248b3ee29da357ba8d0.tar.bz2 | |
Visual/edit modes: yet more minor changes.
- Use a has for singletons (as it was previously), but with a distinct
  identity generated by Utils.getIdentity.
- Fix counts not be using in a number of places.
Diffstat (limited to 'content_scripts/mode.coffee')
| -rw-r--r-- | content_scripts/mode.coffee | 15 | 
1 files changed, 6 insertions, 9 deletions
| diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index e7a4e0ee..bda8672c 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -91,10 +91,11 @@ class Mode      # be unique.  New instances deactivate existing instances with the same key.      if @options.singleton        do => +        singletons = Mode.singletons ||= {} +        key = Utils.getIdentity @options.singleton +        @onExit -> delete singletons[key]          @deactivateSingleton @options.singleton -        @onExit => Mode.singletons = Mode.singletons.filter (active) => active.key != @options.singleton -        Mode.singletons.push key: @options.singleton, mode: @ -        console.log "singletons:", (Mode.singletons.map (active) -> active.mode.id)... if @debug +        singletons[key] = @      # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys,      # and calls @registerStateChange() (if defined) whenever the state changes. The mode also tracks the @@ -137,12 +138,8 @@ class Mode        Mode.updateBadge()        @modeIsActive = false -  deactivateSingleton: (key) -> -    Mode.singletons ||= [] -    for active in Mode.singletons -      if active.key == key and active.mode.modeIsActive -        console.log "singleton, deactivating:", active.mode.id if @debug -        active.mode.exit() +  deactivateSingleton: (singleton) -> +    Mode.singletons?[Utils.getIdentity singleton]?.exit()    # The badge is chosen by bubbling an "updateBadge" event down the handler stack allowing each mode the    # opportunity to choose a badge. This is overridden in sub-classes. | 
