From 5146abb7e11bfcd59a2426a6de00c77f3f5588c9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 28 Mar 2012 10:17:46 -0700 Subject: [PATCH] Eliminate Editor.getCursor --- spec/atom/command-interpreter-spec.coffee | 21 ++++++++++++--------- spec/atom/editor-spec.coffee | 4 ++-- src/atom/editor.coffee | 5 ++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/spec/atom/command-interpreter-spec.coffee b/spec/atom/command-interpreter-spec.coffee index ea4ecd7d2..1e2799e84 100644 --- a/spec/atom/command-interpreter-spec.coffee +++ b/spec/atom/command-interpreter-spec.coffee @@ -43,15 +43,15 @@ describe "CommandInterpreter", -> describe ".", -> it 'maintains the current selection', -> - editor.getSelection().setBufferRange([[1,1], [2,2]]) + editor.setSelectionBufferRange([[1,1], [2,2]]) interpreter.eval(editor, '.') expect(editor.getSelection().getBufferRange()).toEqual [[1,1], [2,2]] - editor.getSelection().setBufferRange([[1,1], [2,2]]) + editor.setSelectionBufferRange([[1,1], [2,2]]) interpreter.eval(editor, '.,') expect(editor.getSelection().getBufferRange()).toEqual [[1,1], [12,2]] - editor.getSelection().setBufferRange([[1,1], [2,2]]) + editor.setSelectionBufferRange([[1,1], [2,2]]) interpreter.eval(editor, ',.') expect(editor.getSelection().getBufferRange()).toEqual [[0,0], [2,2]] @@ -131,18 +131,21 @@ describe "CommandInterpreter", -> describe "substitution", -> it "does nothing if there are no matches", -> - editor.getSelection().setBufferRange([[6, 0], [6, 44]]) + editor.setSelectionBufferRange([[6, 0], [6, 44]]) interpreter.eval(editor, 's/not-in-text/foo/') expect(buffer.lineForRow(6)).toBe ' current < pivot ? left.push(current) : right.push(current);' - it "performs a single substitution within the current selection", -> - editor.getSelection().setBufferRange([[6, 0], [6, 44]]) - interpreter.eval(editor, 's/current/foo/') - expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(current) : right.push(current);' + describe "when not global", -> + describe "when there is a single selection", -> + it "performs a single substitution within the current selection", -> + editor.setSelectionBufferRange([[6, 0], [6, 44]]) + interpreter.eval(editor, 's/current/foo/') + expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(current) : right.push(current);' describe "when suffixed with a g", -> + describe "when global", -> it "performs a multiple substitutions within the current selection", -> - editor.getSelection().setBufferRange([[6, 0], [6, 44]]) + editor.setSelectionBufferRange([[6, 0], [6, 44]]) interpreter.eval(editor, 's/current/foo/g') expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);' diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index c5bb13e7e..5350e0af4 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -202,7 +202,7 @@ describe "Editor", -> editor.setCursorScreenPosition(row: 2, column: 2) it "moves the cursor to the character at the given row and column", -> - expect(editor.getCursor().position()).toEqual(top: 2 * editor.lineHeight, left: 2 * editor.charWidth) + expect(editor.find('.cursor').position()).toEqual(top: 2 * editor.lineHeight, left: 2 * editor.charWidth) describe "if soft-wrap is enabled", -> beforeEach -> @@ -1345,7 +1345,7 @@ describe "Editor", -> expect(editor.lineHeight).not.toBeNull() expect(editor.charWidth).not.toBeNull() - expect(editor.getCursor().offset()).toEqual pagePixelPositionForPoint(editor, [2, 2]) + expect(editor.find('.cursor').offset()).toEqual pagePixelPositionForPoint(editor, [2, 2]) it "is focused", -> editor.attachToDom() diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index ac3460f8e..5f5c377c2 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -345,15 +345,14 @@ class Editor extends View @lineHeight = fragment.outerHeight() fragment.remove() - getCursor: (index) -> @compositeCursor.getCursor(index) moveCursorUp: -> @compositeCursor.moveUp() moveCursorDown: -> @compositeCursor.moveDown() moveCursorRight: -> @compositeCursor.moveRight() moveCursorLeft: -> @compositeCursor.moveLeft() setCursorScreenPosition: (position) -> @compositeCursor.setScreenPosition(position) - getCursorScreenPosition: -> @getCursor().getScreenPosition() + getCursorScreenPosition: -> @compositeCursor.getCursor().getScreenPosition() setCursorBufferPosition: (position) -> @compositeCursor.setBufferPosition(position) - getCursorBufferPosition: -> @getCursor().getBufferPosition() + getCursorBufferPosition: -> @compositeCursor.getCursor().getBufferPosition() getSelection: (index) -> @compositeSelection.getSelection(index) getSelections: -> @compositeSelection.getSelections()