diff options
| author | Stephen Blott | 2015-04-18 08:59:58 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-04-18 10:23:17 +0100 |
| commit | 000a7030c0a3c95b2914d0a65f0ef87891b2e448 (patch) | |
| tree | ccd559c04f48d03f8667c7957b8f0fa424305cff | |
| parent | 6224319dcfa5eed1d9d9fab3a5fc2d0c20b70c2e (diff) | |
| download | vimium-000a7030c0a3c95b2914d0a65f0ef87891b2e448.tar.bz2 | |
Mode indicator: initial move to HUD.
| -rw-r--r-- | content_scripts/mode.coffee | 10 | ||||
| -rw-r--r-- | content_scripts/mode_insert.coffee | 1 | ||||
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 28 |
4 files changed, 31 insertions, 15 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 292dc24e..ad66f2d7 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -51,6 +51,14 @@ class Mode keydown: @options.keydown || null keypress: @options.keypress || null keyup: @options.keyup || null + indicator: => + # Update the mode indicator. Setting @options.indicator to a string shows a mode indicator in the + # HUD. Setting @options.indicator to 'false' forces no mode indicator. If @options.indicator is + # undefined, then the request propagates to the next mode. + if @options.indicator? + if @options.indicator then HUD?.show @options.indicator else HUD?.hide true, false + @stopBubblingAndTrue + else @continueBubbling # If @options.exitOnEscape is truthy, then the mode will exit when the escape key is pressed. if @options.exitOnEscape @@ -122,6 +130,7 @@ class Mode if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue Mode.modes.push @ + handlerStack.bubbleEvent 'indicator' @logModes() # End of Mode constructor. @@ -143,6 +152,7 @@ class Mode handlerStack.remove handlerId for handlerId in @handlers Mode.modes = Mode.modes.filter (mode) => mode != @ @modeIsActive = false + handlerStack.bubbleEvent 'indicator' deactivateSingleton: (singleton) -> Mode.singletons?[Utils.getIdentity singleton]?.exit() diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index c0f4c6e7..825229f7 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -24,6 +24,7 @@ class InsertMode extends Mode defaults = name: "insert" + indicator: if @global then "Insert mode" else null keypress: handleKeyEvent keyup: handleKeyEvent keydown: handleKeyEvent diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 9b01094b..7a94831c 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -376,10 +376,10 @@ class Movement extends CountPrefix message = @yankedText.replace /\s+/g, " " message = message[...12] + "..." if 15 < @yankedText.length plural = if @yankedText.length == 1 then "" else "s" - HUD.showForDuration "Yanked #{@yankedText.length} character#{plural}: \"#{message}\".", 2500 @options.onYank?.call @, @yankedText @exit() + HUD.showForDuration "Yanked #{@yankedText.length} character#{plural}: \"#{message}\".", 2500 @yankedText exit: (event, target) -> @@ -466,6 +466,7 @@ class VisualMode extends Movement defaults = name: "visual" + indicator: if options.indicator? then options.indicator else "Visual mode" singleton: VisualMode exitOnEscape: true super extend defaults, options @@ -566,7 +567,7 @@ class VisualMode extends Movement class VisualLineMode extends VisualMode constructor: (options = {}) -> - super extend { name: "visual/line" }, options + super extend { name: "visual/line", indicator: "Visual mode (line)" }, options @extendSelection() @commands.v = -> @changeMode VisualMode @@ -586,6 +587,7 @@ class CaretMode extends Movement defaults = name: "caret" + indicator: "Caret mode" singleton: VisualMode exitOnEscape: true super extend defaults, options @@ -650,6 +652,7 @@ class EditMode extends Movement defaults = name: "edit" + indicator: "Edit mode" exitOnEscape: true exitOnBlur: @element super extend defaults, options diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index cc8d820c..74f61995 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -129,6 +129,7 @@ window.initializeModes = -> constructor: -> super name: "normal" + indicator: false # There is no mode indicator in normal mode. keydown: (event) => onKeydown.call @, event keypress: (event) => onKeypress.call @, event keyup: (event) => onKeyup.call @, event @@ -691,7 +692,6 @@ handleKeyCharForFindMode = (keyChar) -> updateQueryForFindMode findModeQuery.rawQuery + keyChar handleEscapeForFindMode = -> - exitFindMode() document.body.classList.remove("vimiumFindMode") # removing the class does not re-color existing selections. we recreate the current selection so it reverts # back to the default color. @@ -705,7 +705,7 @@ handleEscapeForFindMode = -> # Return true if character deleted, false otherwise. handleDeleteForFindMode = -> if findModeQuery.rawQuery.length == 0 - exitFindMode() + HUD.hide() performFindInPlace() false else @@ -716,7 +716,6 @@ handleDeleteForFindMode = -> # <esc> corresponds approximately to 'nevermind, I have found it already' while <cr> means 'I want to save # this query and do more searches with it' handleEnterForFindMode = -> - exitFindMode() focusFoundLink() document.body.classList.add("vimiumFindMode") FindModeHistory.saveQuery findModeQuery.rawQuery @@ -727,6 +726,7 @@ class FindMode extends Mode @partialQuery = "" super name: "find" + indicator: false exitOnEscape: true exitOnClick: true @@ -991,11 +991,9 @@ window.enterFindMode = -> # Save the selection, so performFindInPlace can restore it. findModeSaveSelection() findModeQuery = { rawQuery: "" } - HUD.show("/") - new FindMode() - -exitFindMode = -> - HUD.hide() + findMode = new FindMode() + HUD.show "/" + findMode window.showHelpDialog = (html, fid) -> return if (isShowingHelpDialog || !document.body || fid != frameId) @@ -1098,13 +1096,17 @@ HUD = document.body.appendChild(element) element - hide: (immediate) -> + # Hide the HUD. + # If :immediate is falsy, then the HUD is faded out smoothly (otherwise it is hidden immediately). + # If :updateIndicator is truthy, then we also refresh the mode indicator. The only time we don't update the + # mode indicator, is when hide() is called for the mode indicator itself. + hide: (immediate = false, updateIndicator = true) -> clearInterval(HUD._tweenId) - if (immediate) - HUD.displayElement().style.display = "none" + if immediate + HUD.displayElement().style.display = "none" unless updateIndicator + handlerStack.bubbleEvent "indicator" if updateIndicator else - HUD._tweenId = Tween.fade(HUD.displayElement(), 0, 150, - -> HUD.displayElement().style.display = "none") + HUD._tweenId = Tween.fade HUD.displayElement(), 0, 150, -> HUD.hide true, updateIndicator isReady: -> document.body != null |
