diff options
| author | Stephen Blott | 2015-01-25 17:08:17 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-25 17:08:17 +0000 |
| commit | 7bf8a6a4a9bf10985f0f211fda72a1ee759ab389 (patch) | |
| tree | f1ff044840a76d0536c79f4dbf8ee292f960dcc3 /content_scripts | |
| parent | fa8cc2250e8b8956e62e1474ee0aa08e433accba (diff) | |
| download | vimium-7bf8a6a4a9bf10985f0f211fda72a1ee759ab389.tar.bz2 | |
Visual/edit modes: miscellaneous improvements.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 91da063b..7aa6858d 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -144,6 +144,7 @@ class Movement extends MaintainCount @commands = {} @alterMethod = options.alterMethod || "extend" @keyQueue = "" + @keyPressCount = 0 @yankedText = "" super options @@ -160,6 +161,7 @@ class Movement extends MaintainCount @push _name: "#{@id}/keypress" keypress: (event) => + @keyPressCount += 1 unless event.metaKey or event.ctrlKey or event.altKey @keyQueue += String.fromCharCode event.charCode # We allow at most three characters for a command or movement mapping. @@ -274,6 +276,7 @@ class VisualMode extends Movement when "Caret" # Try to start with a visible selection. @moveInDirection(forward) or @moveInDirection backward unless options.underEditMode + @scrollIntoView() if @selection.type == "Range" defaults = name: "visual" @@ -284,25 +287,33 @@ class VisualMode extends Movement super extend defaults, options extend @commands, + "V": -> new VisualLineMode extend @options, initialRange: @selection.getRangeAt(0).cloneRange() "y": -> # Special case: "yy" (the first from edit mode, and now the second). - @selectLine() if @options.yYanksLine + @selectLine() if @options.yYanksLine and @keyPressCount == 1 @yank() - "V": -> new VisualLineMode extend @options, initialRange: @selection.getRangeAt(0).cloneRange() if @options.underEditMode extend @commands, - "d": -> @yank deleteFromDocument: true "c": -> @yank(); enterInsertMode() - else + "d": -> + # Special case: "dd" (the first from edit mode, and now the second). + @selectLine() if @options.dYanksLine and @keyPressCount == 1 + @yank deleteFromDocument: true + + unless @options.underEditMode @installFindMode() + # Grab the initial clipboard contents. We'll try to keep them intact until we get an explicit yank. @clipboardContents = "" - @paste (text) => @clipboardContents = text + @paste (text) => + @clipboardContents = text if text + # + # End of VisualMode constructor. protectClipboard: (func) -> func() - @copy @clipboardContents + @copy @clipboardContents if @clipboardContents copy: (text) -> super @clipboardContents = text @@ -399,10 +410,8 @@ class EditMode extends Movement "Y": -> @enterVisualMode runMovement: "Y" "y": => @enterVisualMode yYanksLine: true - "d": => @enterVisualMode deleteFromDocument: true - "c": => @enterVisualMode - deleteFromDocument: true - onYank: enterInsertMode + "d": => @enterVisualMode deleteFromDocument: true, dYanksLine: true + "c": => @enterVisualMode deleteFromDocument: true, onYank: enterInsertMode "D": => @enterVisualMode runMovement: "$", deleteFromDocument: true "C": => @enterVisualMode runMovement: "$", deleteFromDocument: true, onYank: enterInsertMode @@ -420,6 +429,7 @@ class EditMode extends Movement enterVisualMode: (options = {}) -> defaults = + badge: "" underEditMode: true initialCount: @countPrefix oneMovementOnly: true |
