From f712ca2a22582eccabe844d699991642fb6c26f5 Mon Sep 17 00:00:00 2001 From: Isaac Hess Date: Mon, 13 Oct 2014 09:06:35 -0600 Subject: [PATCH 1/2] Changed yank so it moves cursor to beginning of selection rather than end --- lib/operators/general-operators.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/operators/general-operators.coffee b/lib/operators/general-operators.coffee index 9077682b..4aa238f8 100644 --- a/lib/operators/general-operators.coffee +++ b/lib/operators/general-operators.coffee @@ -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() + selectionRange = selection.getScreenRange() + newPosition = selectionRange.start else text = '' type = if @motion.isLinewise?() then 'linewise' else 'character' @@ -155,7 +155,7 @@ class Yank extends Operator @vimState.setRegister(@register, {text, type}) - @editor.setCursorScreenPosition(originalPosition) + @editor.setCursorScreenPosition(newPosition) @vimState.activateCommandMode() # From 128775e42d295a63dbcee5fb1892315123a150eb Mon Sep 17 00:00:00 2001 From: Isaac Hess Date: Wed, 15 Oct 2014 08:34:32 -0600 Subject: [PATCH 2/2] Updated tests --- spec/operators-spec.coffee | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spec/operators-spec.coffee b/spec/operators-spec.coffee index c324d26c..03f93310 100644 --- a/spec/operators-spec.coffee +++ b/spec/operators-spec.coffee @@ -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 -> @@ -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 -> @@ -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", -> @@ -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", ->