Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/operators/general-operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
#
Expand All @@ -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.
#
Expand Down
6 changes: 3 additions & 3 deletions lib/vim-state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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, @)]
Expand Down
42 changes: 39 additions & 3 deletions spec/operators-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ describe "Operators", ->
commandModeInputKeydown('a')
expect(vimState.getMark('a')).toEqual [0,1]

describe 'the ~ keybinding', ->
describe 'the g~ keybinding', ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the ~/g~ keybindings ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same below for gU and gu please

beforeEach ->
editor.setText('aBc\nXyZ')
editor.setCursorBufferPosition([0, 0])
Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand All @@ -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')
Expand Down