From ba8ca3d160c94d66619cb022ac93c8da7f0babc5 Mon Sep 17 00:00:00 2001 From: Daan De Deckere Date: Tue, 7 Apr 2015 13:35:14 +0200 Subject: [PATCH 1/5] Make gUgU, gugu and g~g~ change casing on the whole line --- lib/vim-state.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vim-state.coffee b/lib/vim-state.coffee index 1a369556..aa883761 100644 --- a/lib/vim-state.coffee +++ b/lib/vim-state.coffee @@ -83,9 +83,9 @@ class VimState 'delete-right': => [new Operators.Delete(@editor, @), new Motions.MoveRight(@editor, @)] 'delete-left': => [new Operators.Delete(@editor, @), new Motions.MoveLeft(@editor, @)] 'delete-to-last-character-of-line': => [new Operators.Delete(@editor, @), new Motions.MoveToLastCharacterOfLine(@editor, @)] - 'toggle-case': => new Operators.ToggleCase(@editor, @) - 'upper-case': => new Operators.UpperCase(@editor, @) - 'lower-case': => new Operators.LowerCase(@editor, @) + 'toggle-case': => @linewiseAliasedOperator(Operators.ToggleCase) + 'upper-case': => @linewiseAliasedOperator(Operators.UpperCase) + 'lower-case': => @linewiseAliasedOperator(Operators.LowerCase) 'toggle-case-now': => new Operators.ToggleCase(@editor, @, complete: true) 'yank': => @linewiseAliasedOperator(Operators.Yank) 'yank-line': => [new Operators.Yank(@editor, @), new Motions.MoveToRelativeLine(@editor, @)] From 217bba8a9cb0cc2722d295a1934e0523d7a19548 Mon Sep 17 00:00:00 2001 From: Daan De Deckere Date: Tue, 7 Apr 2015 14:18:56 +0200 Subject: [PATCH 2/5] update specs with new case switching --- spec/operators-spec.coffee | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/spec/operators-spec.coffee b/spec/operators-spec.coffee index 343112d3..a60a4990 100644 --- a/spec/operators-spec.coffee +++ b/spec/operators-spec.coffee @@ -1293,7 +1293,7 @@ describe "Operators", -> commandModeInputKeydown('a') expect(vimState.getMark('a')).toEqual [0,1] - describe 'the ~ keybinding', -> + describe 'the g~ keybinding', -> beforeEach -> editor.setText('aBc\nXyZ') editor.setCursorBufferPosition([0, 0]) @@ -1335,7 +1335,18 @@ describe "Operators", -> keydown("l") expect(editor.getText()).toBe 'Abc\nXyZ' - describe 'the U keybinding', -> + describe "when followed by g~", -> + it "toggles the case of the whole line", -> + editor.setCursorBufferPosition([2, 2]) + + keydown('g') + keydown('~') + keydown('g') + keydown('~') + + expect(editor.getText()).toBe "aBc\nxYz" + + describe 'the gU keybinding', -> beforeEach -> editor.setText('aBc\nXyZ') editor.setCursorBufferPosition([0, 0]) @@ -1356,7 +1367,18 @@ describe "Operators", -> keydown("U", shift: true) expect(editor.getText()).toBe 'ABC\nXyZ' - describe 'the u keybinding', -> + describe "when followed by gU", -> + it "makes the whole line uppercase", -> + editor.setCursorBufferPosition([2, 2]) + + keydown('g') + keydown('U', shift: true) + keydown('g') + keydown('U', shift: true) + + expect(editor.getText()).toBe "aBc\nXYZ" + + describe 'the gu keybinding', -> beforeEach -> editor.setText('aBc\nXyZ') editor.setCursorBufferPosition([0, 0]) @@ -1372,6 +1394,17 @@ describe "Operators", -> keydown("u") expect(editor.getText()).toBe 'abc\nXyZ' + describe "when followed by gu", -> + it "makes the whole line lowercase", -> + editor.setCursorBufferPosition([2, 2]) + + keydown('g') + keydown('u') + keydown('g') + keydown('u') + + expect(editor.getText()).toBe "aBc\nxyz" + describe "the i keybinding", -> beforeEach -> editor.setText('123\n4567') From 602f5c1c7a45101b0f6cdb4d0c1931390ed4bd82 Mon Sep 17 00:00:00 2001 From: Daan De Deckere Date: Tue, 7 Apr 2015 16:07:00 +0200 Subject: [PATCH 3/5] when running a case switch motion on the whole line, the cursor should end up on the first character of that line. Could not find a cleaner solution for now. --- lib/operators/general-operators.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/operators/general-operators.coffee b/lib/operators/general-operators.coffee index 0d29af83..a55e36ee 100644 --- a/lib/operators/general-operators.coffee +++ b/lib/operators/general-operators.coffee @@ -142,6 +142,10 @@ class ToggleCase extends Operator @vimState.activateCommandMode() + if @motion.isLinewise?() + @editor.moveToPreviousWordBoundary() + @editor.moveToFirstCharacterOfLine() + # # In visual mode or after `g` with a motion, it makes the selection uppercase # @@ -156,6 +160,10 @@ class UpperCase extends Operator @vimState.activateCommandMode() + if @motion.isLinewise?() + @editor.moveToPreviousWordBoundary() + @editor.moveToFirstCharacterOfLine() + # # In visual mode or after `g` with a motion, it makes the selection lowercase # @@ -170,6 +178,10 @@ class LowerCase extends Operator @vimState.activateCommandMode() + if @motion.isLinewise?() + @editor.moveToPreviousWordBoundary() + @editor.moveToFirstCharacterOfLine() + # # It copies everything selected by the following motion. # From 387eeb5971cd1c923d08f7d1ce167f30e5284b53 Mon Sep 17 00:00:00 2001 From: Daan De Deckere Date: Tue, 7 Apr 2015 17:10:32 +0200 Subject: [PATCH 4/5] check if motion is defined first --- lib/operators/general-operators.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/operators/general-operators.coffee b/lib/operators/general-operators.coffee index a55e36ee..d260bc87 100644 --- a/lib/operators/general-operators.coffee +++ b/lib/operators/general-operators.coffee @@ -142,7 +142,7 @@ class ToggleCase extends Operator @vimState.activateCommandMode() - if @motion.isLinewise?() + if @motion? and @motion.isLinewise?() @editor.moveToPreviousWordBoundary() @editor.moveToFirstCharacterOfLine() @@ -160,7 +160,7 @@ class UpperCase extends Operator @vimState.activateCommandMode() - if @motion.isLinewise?() + if @motion? and @motion.isLinewise?() @editor.moveToPreviousWordBoundary() @editor.moveToFirstCharacterOfLine() @@ -178,7 +178,7 @@ class LowerCase extends Operator @vimState.activateCommandMode() - if @motion.isLinewise?() + if @motion and @motion.isLinewise?() @editor.moveToPreviousWordBoundary() @editor.moveToFirstCharacterOfLine() From 58d7088efa44818a9ab6c58b5fc865b200d4f78c Mon Sep 17 00:00:00 2001 From: Daan De Deckere Date: Tue, 7 Apr 2015 17:11:17 +0200 Subject: [PATCH 5/5] update spec to test whether cursor moves to first character of line when performing a case switch on a whole line --- spec/operators-spec.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/operators-spec.coffee b/spec/operators-spec.coffee index a60a4990..652f2d37 100644 --- a/spec/operators-spec.coffee +++ b/spec/operators-spec.coffee @@ -1336,8 +1336,8 @@ describe "Operators", -> expect(editor.getText()).toBe 'Abc\nXyZ' describe "when followed by g~", -> - it "toggles the case of the whole line", -> - editor.setCursorBufferPosition([2, 2]) + it "toggles the case of the whole line, and the cursor ends up on the first character of that line", -> + editor.setCursorBufferPosition([1, 1]) keydown('g') keydown('~') @@ -1345,6 +1345,7 @@ describe "Operators", -> keydown('~') expect(editor.getText()).toBe "aBc\nxYz" + expect(editor.getCursorScreenPosition()).toEqual [1, 0] describe 'the gU keybinding', -> beforeEach -> @@ -1368,8 +1369,8 @@ describe "Operators", -> expect(editor.getText()).toBe 'ABC\nXyZ' describe "when followed by gU", -> - it "makes the whole line uppercase", -> - editor.setCursorBufferPosition([2, 2]) + it "makes the whole line uppercase, and the cursor ends up on the first character of that line", -> + editor.setCursorBufferPosition([1, 1]) keydown('g') keydown('U', shift: true) @@ -1377,6 +1378,7 @@ describe "Operators", -> keydown('U', shift: true) expect(editor.getText()).toBe "aBc\nXYZ" + expect(editor.getCursorBufferPosition()).toEqual [1, 0] describe 'the gu keybinding', -> beforeEach -> @@ -1395,8 +1397,8 @@ describe "Operators", -> expect(editor.getText()).toBe 'abc\nXyZ' describe "when followed by gu", -> - it "makes the whole line lowercase", -> - editor.setCursorBufferPosition([2, 2]) + it "makes the whole line lowercase, and the cursor ends up on the first character of that line", -> + editor.setCursorBufferPosition([1, 1]) keydown('g') keydown('u') @@ -1404,6 +1406,7 @@ describe "Operators", -> keydown('u') expect(editor.getText()).toBe "aBc\nxyz" + expect(editor.getCursorScreenPosition()).toEqual [1, 0] describe "the i keybinding", -> beforeEach ->