From 5d199e6c786bb2874f7ecb700d505e7b2d70d982 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 8 Jan 2015 07:44:53 +0000 Subject: Modes; refactor and simplify. - Insert mode trigger and blocker. - Better comments for PostFindMode. - Better comments for FocusSelector. - Make insert mode consistent with master. --- content_scripts/mode_find.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 837606f3..2ef74a89 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -1,7 +1,7 @@ # NOTE(smblott). Ultimately, all of the FindMode-related code should be moved to this file. # When we use find mode, the selection/focus can end up in a focusable/editable element. In this situation, -# PostFindMode handles three special cases: +# special considerations apply. We implement three special cases: # 1. Be an InsertModeBlocker. This prevents keyboard events from dropping us unintentionally into insert # mode. This is achieved by inheriting from InsertModeBlocker. # 2. Prevent all keyboard events on the active element from propagating. This is achieved by setting the @@ -16,12 +16,15 @@ class PostFindMode extends InsertModeBlocker super name: "post-find" + # Be a singleton. That way, we don't have to keep track of any currently-active instance. Such an + # instance is automatically deactivated when a new instance is created. singleton: PostFindMode trapAllKeyboardEvents: element return @exit() unless element and findModeAnchorNode - # Special cases only arise if the active element can take input. So, exit immediately if it cannot. + # Special considerations only arise if the active element can take input. So, exit immediately if it + # cannot. canTakeInput = DomUtils.isSelectable(element) and DomUtils.isDOMDescendant findModeAnchorNode, element canTakeInput ||= element.isContentEditable canTakeInput ||= findModeAnchorNode.parentElement?.isContentEditable -- cgit v1.2.3