From c1c8cb71383f3f36df6c93ba106cc51f03666e78 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 24 Apr 2017 20:41:42 +0100 Subject: Make Mode::exit idempotent --- content_scripts/mode.coffee | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 85187b2c..9de423ff 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -173,15 +173,16 @@ class Mode @exitHandlers.push handler exit: (args...) -> - if @modeIsActive - @log "deactivate:", @id - unless @modeIsExiting - @modeIsExiting = true - handler args... for handler in @exitHandlers - handlerStack.remove handlerId for handlerId in @handlers - Mode.modes = Mode.modes.filter (mode) => mode != this - @modeIsActive = false - @setIndicator() + return if @modeIsExiting or not @modeIsActive + @log "deactivate:", @id + @modeIsExiting = true + + handler args... for handler in @exitHandlers + handlerStack.remove handlerId for handlerId in @handlers + Mode.modes = Mode.modes.filter (mode) => mode != this + + @modeIsActive = false + @setIndicator() # Debugging routines. logModes: -> -- cgit v1.2.3