From 03ef7f2a8525e8fbfc67b04d7a0ce47522449d03 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 11:42:25 +0100 Subject: Refactor to avoid having to cover all keyboard event cases. It's pretty common that we want to suppress all keyboard events, so let's support that in modes.coffee, thereby simplifying handlers elsewhere. --- content_scripts/mode.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index f631b4cd..b2019ef9 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -47,6 +47,15 @@ class Mode @id = "#{@name}-#{@count}" @log "activate:", @id + # If options.suppressAllKeyboardEvents is truthy, then all keyboard events are suppressed. This avoids + # the need for modes which block all keyboard events to 1) provide handlers for all keyboard events, + # and 2) worry about their return value. + if options.suppressAllKeyboardEvents + for type in [ "keydown", "keypress", "keyup" ] + do (type) -> + handler = options[type] + options[type] = (event) -> handler? event; false + @push keydown: @options.keydown || null keypress: @options.keypress || null -- cgit v1.2.3 From e79fe062bc84b1530ec266a12f9323aa53cb89e4 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 12:02:47 +0100 Subject: Fix tests for #1713... ... which is weird, because the tests are passing here. Let's see what Travis makes of this. --- content_scripts/mode.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index b2019ef9..cbcc15f7 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -50,11 +50,11 @@ class Mode # If options.suppressAllKeyboardEvents is truthy, then all keyboard events are suppressed. This avoids # the need for modes which block all keyboard events to 1) provide handlers for all keyboard events, # and 2) worry about their return value. - if options.suppressAllKeyboardEvents + if @options.suppressAllKeyboardEvents for type in [ "keydown", "keypress", "keyup" ] - do (type) -> - handler = options[type] - options[type] = (event) -> handler? event; false + do (type) => + handler = @options[type] + @options[type] = (event) -> handler? event; false @push keydown: @options.keydown || null -- cgit v1.2.3 From 291e7fd67de9e1c4bd0bc5048ab7344424f19b30 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 15:27:45 +0100 Subject: Re-implement Marks, incl `` binding. --- content_scripts/mode.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index cbcc15f7..22b6120f 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -54,7 +54,7 @@ class Mode for type in [ "keydown", "keypress", "keyup" ] do (type) => handler = @options[type] - @options[type] = (event) -> handler? event; false + @options[type] = (event) => handler? event; @stopBubblingAndFalse @push keydown: @options.keydown || null -- cgit v1.2.3 From 8dab334fa2fde9d4815ce0a12c0d2ab9dd44ff05 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 16:15:31 +0100 Subject: Also set previous position for before global mark movement. --- content_scripts/mode.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 22b6120f..86d3e011 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -52,8 +52,7 @@ class Mode # and 2) worry about their return value. if @options.suppressAllKeyboardEvents for type in [ "keydown", "keypress", "keyup" ] - do (type) => - handler = @options[type] + do (handler = @options[type]) => @options[type] = (event) => handler? event; @stopBubblingAndFalse @push -- cgit v1.2.3 From 1c4daf625949451178a349e93811b04a00472835 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 19:15:54 +0100 Subject: Modes, better comments. --- content_scripts/mode.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 86d3e011..9105fabb 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -48,8 +48,8 @@ class Mode @log "activate:", @id # If options.suppressAllKeyboardEvents is truthy, then all keyboard events are suppressed. This avoids - # the need for modes which block all keyboard events to 1) provide handlers for all keyboard events, - # and 2) worry about their return value. + # the need for modes which block all keyboard events 1) to provide handlers for all keyboard events, + # and 2) to worry about their return values. if @options.suppressAllKeyboardEvents for type in [ "keydown", "keypress", "keyup" ] do (handler = @options[type]) => -- cgit v1.2.3 From 50980718d848ca324b6fca0568e2fa7203d51d52 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 5 Jun 2015 05:04:56 +0100 Subject: Fix event suppression for Marks keyboard events. --- content_scripts/mode.coffee | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 9105fabb..ffabc111 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -48,12 +48,11 @@ class Mode @log "activate:", @id # If options.suppressAllKeyboardEvents is truthy, then all keyboard events are suppressed. This avoids - # the need for modes which block all keyboard events 1) to provide handlers for all keyboard events, - # and 2) to worry about their return values. + # the need for modes which suppress all keyboard events 1) to provide handlers for all of those events, + # or 2) to worry about event suppression and event-handler return values. if @options.suppressAllKeyboardEvents for type in [ "keydown", "keypress", "keyup" ] - do (handler = @options[type]) => - @options[type] = (event) => handler? event; @stopBubblingAndFalse + @options[type] = @alwaysSuppressEvent @options[type] @push keydown: @options.keydown || null @@ -179,6 +178,13 @@ class Mode # case), because they do not need to be concerned with the value they yield. alwaysContinueBubbling: handlerStack.alwaysContinueBubbling + # Shorthand for an event handler which always suppresses event propagation. + alwaysSuppressEvent: (handler = null) -> + (event) => + handler? event + DomUtils.suppressPropagation event + @stopBubblingAndFalse + # Activate a new instance of this mode, together with all of its original options (except its main # keybaord-event handlers; these will be recreated). cloneMode: -> -- cgit v1.2.3