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
10 changes: 5 additions & 5 deletions lib/operators/general-operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class Yank extends Operator
#
# Returns nothing.
execute: (count=1) ->
originalPosition = @editor.getCursorScreenPosition()
selection = @editor.getLastSelection()
if _.contains(@motion.select(count), true)
selectedPosition = @editor.getCursorScreenPosition()
text = @editor.getSelection().getText()
originalPosition = Point.min(originalPosition, selectedPosition)
text = @editor.getLastSelection().getText()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be selection.getText() since you already have the selection variable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Never mind, I'm assuming that line 145 may have changed the selection so you would need to re-grab it?

selectionRange = selection.getScreenRange()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rather than just measure the screen position, we get the range of the selection and use that to check the selection position.

newPosition = selectionRange.start
else
text = ''
type = if @motion.isLinewise?() then 'linewise' else 'character'
Expand All @@ -155,7 +155,7 @@ class Yank extends Operator

@vimState.setRegister(@register, {text, type})

@editor.setCursorScreenPosition(originalPosition)
@editor.setCursorScreenPosition(newPosition)
@vimState.activateCommandMode()

#
Expand Down
18 changes: 11 additions & 7 deletions spec/operators-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ describe "Operators", ->
it "saves the line to the default register", ->
expect(vimState.getRegister('"').text).toBe "012 345\n"

it "leaves the cursor at the starting position", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
# FIXME: Get cursor to stay in original position
it "Moves the cursor to the start of the selection", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]

describe "when followed with a repeated y", ->
beforeEach ->
Expand All @@ -450,8 +451,9 @@ describe "Operators", ->
it "copies n lines, starting from the current", ->
expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"

it "leaves the cursor at the starting position", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
# FIXME: Get cursor to stay in original position
it "Moves the cursor to the start of the selection", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]

describe "with a register", ->
beforeEach ->
Expand Down Expand Up @@ -493,8 +495,9 @@ describe "Operators", ->
it "saves both full lines to the default register", ->
expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"

it "leaves the cursor at the starting position", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
# FIXME: Get cursor to stay in original position
it "Moves the cursor to the start of the selection", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]

describe "the yy keybinding", ->
describe "on a single line file", ->
Expand Down Expand Up @@ -541,7 +544,8 @@ describe "Operators", ->
keydown('Y', shift: true)

expect(vimState.getRegister('"').text).toBe "012 345\n"
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
# FIXME: Get cursor to stay in original position
expect(editor.getCursorScreenPosition()).toEqual [0, 0]

describe "the p keybinding", ->
describe "with character contents", ->
Expand Down