diff --git a/lib/operators/general-operators.coffee b/lib/operators/general-operators.coffee index 0d29af83..d260bc87 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? and @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? and @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 and @motion.isLinewise?() + @editor.moveToPreviousWordBoundary() + @editor.moveToFirstCharacterOfLine() + # # It copies everything selected by the following motion. # 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, @)] diff --git a/spec/operators-spec.coffee b/spec/operators-spec.coffee index 343112d3..652f2d37 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,19 @@ 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, and the cursor ends up on the first character of that line", -> + editor.setCursorBufferPosition([1, 1]) + + keydown('g') + keydown('~') + keydown('g') + keydown('~') + + expect(editor.getText()).toBe "aBc\nxYz" + expect(editor.getCursorScreenPosition()).toEqual [1, 0] + + describe 'the gU keybinding', -> beforeEach -> editor.setText('aBc\nXyZ') editor.setCursorBufferPosition([0, 0]) @@ -1356,7 +1368,19 @@ 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, and the cursor ends up on the first character of that line", -> + editor.setCursorBufferPosition([1, 1]) + + keydown('g') + keydown('U', shift: true) + keydown('g') + keydown('U', shift: true) + + expect(editor.getText()).toBe "aBc\nXYZ" + expect(editor.getCursorBufferPosition()).toEqual [1, 0] + + describe 'the gu keybinding', -> beforeEach -> editor.setText('aBc\nXyZ') editor.setCursorBufferPosition([0, 0]) @@ -1372,6 +1396,18 @@ describe "Operators", -> keydown("u") expect(editor.getText()).toBe 'abc\nXyZ' + describe "when followed by gu", -> + 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') + keydown('g') + keydown('u') + + expect(editor.getText()).toBe "aBc\nxyz" + expect(editor.getCursorScreenPosition()).toEqual [1, 0] + describe "the i keybinding", -> beforeEach -> editor.setText('123\n4567')