From 3c952ccbfe36d0eb72446275b5e576dda5cac308 Mon Sep 17 00:00:00 2001 From: jazzpi Date: Tue, 16 Aug 2016 00:36:05 +0200 Subject: [PATCH 1/2] Fix mark addresses and add specs for addresses Enables properly parsing marks as addresses. Also adds some specs for addresses by checking how ex-mode behaves when used as a motion. Fixes #70. --- lib/command.coffee | 2 +- spec/ex-commands-spec.coffee | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/command.coffee b/lib/command.coffee index 9097c6c..ffb9b28 100644 --- a/lib/command.coffee +++ b/lib/command.coffee @@ -24,7 +24,7 @@ class Command mark = @vimState.marks[str[1]] unless mark? throw new CommandError("Mark #{str} not set.") - addr = mark.bufferMarker.range.end.row + addr = mark.getEndBufferPosition().row else if str[0] is "/" addr = Find.findNextInBuffer(@editor.buffer, curPos, str[1...-1]) unless addr? diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 72775f8..4db66ce 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -65,6 +65,68 @@ describe "the commands", -> openEx = -> atom.commands.dispatch(editorElement, "ex-mode:open") + describe "as a motion", -> + beforeEach -> + editor.setCursorBufferPosition([0, 0]) + + it "moves the cursor to a specific line", -> + openEx() + submitNormalModeInputText '2' + + expect(editor.getCursorBufferPosition()).toEqual [1, 0] + + it "moves to the second address", -> + openEx() + submitNormalModeInputText '1,3' + + expect(editor.getCursorBufferPosition()).toEqual [2, 0] + + it "works with offsets", -> + openEx() + submitNormalModeInputText '2+1' + expect(editor.getCursorBufferPosition()).toEqual [2, 0] + + openEx() + submitNormalModeInputText '-2' + expect(editor.getCursorBufferPosition()).toEqual [0, 0] + + it "doesn't move when the address is the current line", -> + openEx() + submitNormalModeInputText '.' + expect(editor.getCursorBufferPosition()).toEqual [0, 0] + + openEx() + submitNormalModeInputText ',' + expect(editor.getCursorBufferPosition()).toEqual [0, 0] + + it "moves to the last line", -> + openEx() + submitNormalModeInputText '$' + expect(editor.getCursorBufferPosition()).toEqual [3, 0] + + it "moves to a mark's line", -> + keydown('l') + keydown('m') + commandModeInputKeydown 'a' + keydown('j') + openEx() + submitNormalModeInputText "'a" + expect(editor.getCursorBufferPosition()).toEqual [0, 0] + + it "moves to a specified search", -> + openEx() + submitNormalModeInputText '/def' + expect(editor.getCursorBufferPosition()).toEqual [1, 0] + + openEx() + submitNormalModeInputText '?abc' + expect(editor.getCursorBufferPosition()).toEqual [0, 0] + + editor.setCursorBufferPosition([3, 0]) + openEx() + submitNormalModeInputText '/ef' + expect(editor.getCursorBufferPosition()).toEqual [1, 0] + describe ":write", -> describe "when editing a new file", -> beforeEach -> From 31ac3a98ed407cbaa5429bd04f72487b0c03c6b2 Mon Sep 17 00:00:00 2001 From: jazzpi Date: Tue, 16 Aug 2016 12:33:00 +0200 Subject: [PATCH 2/2] Fix spec for movement to mark --- spec/ex-commands-spec.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 4db66ce..311f18b 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -107,7 +107,7 @@ describe "the commands", -> it "moves to a mark's line", -> keydown('l') keydown('m') - commandModeInputKeydown 'a' + normalModeInputKeydown 'a' keydown('j') openEx() submitNormalModeInputText "'a" @@ -637,7 +637,6 @@ describe "the commands", -> waitsFor -> processedOpStack editor.setText('abc\ndef\nghi\njkl') editor.setCursorBufferPosition([1, 1]) - # For some reason, keydown(':') doesn't work here :/ atom.commands.dispatch(editorElement, 'ex-mode:open') submitNormalModeInputText(',/k/delete') expect(editor.getText()).toEqual('abc\n')