diff --git a/spec/atom/command-interpreter-spec.coffee b/spec/atom/command-interpreter-spec.coffee index 09d5adce5..e8ba55733 100644 --- a/spec/atom/command-interpreter-spec.coffee +++ b/spec/atom/command-interpreter-spec.coffee @@ -21,6 +21,14 @@ describe "CommandInterpreter", -> interpreter.eval(editor, '4,7') expect(editor.selection.getBufferRange()).toEqual [[3, 0], [7, 0]] + describe "$", -> + it "selects EOF", -> + interpreter.eval(editor, '$') + expect(editor.selection.getBufferRange()).toEqual [[12,2], [12,2]] + + interpreter.eval(editor, '1,$') + expect(editor.selection.getBufferRange()).toEqual [[0,0], [12,2]] + describe "substitution", -> it "does nothing if there are no matches", -> editor.selection.setBufferRange([[6, 0], [6, 44]]) diff --git a/src/atom/command-interpreter/address-range.coffee b/src/atom/command-interpreter/address-range.coffee index 2a53def97..a73029f4f 100644 --- a/src/atom/command-interpreter/address-range.coffee +++ b/src/atom/command-interpreter/address-range.coffee @@ -5,5 +5,5 @@ module.exports = class AddressRange extends Address constructor: (@startAddress, @endAddress) -> - getRange: -> - new Range(@startAddress.getRange().start, @endAddress.getRange().end) + getRange: (editor) -> + new Range(@startAddress.getRange(editor).start, @endAddress.getRange(editor).end) diff --git a/src/atom/command-interpreter/address.coffee b/src/atom/command-interpreter/address.coffee index ec3c8b971..36ef72c15 100644 --- a/src/atom/command-interpreter/address.coffee +++ b/src/atom/command-interpreter/address.coffee @@ -1,4 +1,4 @@ module.exports = class Address execute: (editor) -> - editor.getSelection().setBufferRange(@getRange()) + editor.getSelection().setBufferRange(@getRange(editor)) diff --git a/src/atom/command-interpreter/eof-address.coffee b/src/atom/command-interpreter/eof-address.coffee new file mode 100644 index 000000000..7901944f4 --- /dev/null +++ b/src/atom/command-interpreter/eof-address.coffee @@ -0,0 +1,9 @@ +Address = require 'command-interpreter/address' +Range = require 'range' + +module.exports = +class EofAddress extends Address + getRange: (editor) -> + lastRow = editor.getLastBufferRow() + column = editor.getBufferLineLength(lastRow) + new Range([lastRow, column], [lastRow, column]) \ No newline at end of file diff --git a/src/atom/commands.pegjs b/src/atom/commands.pegjs index b9e1101d3..76eae388d 100644 --- a/src/atom/commands.pegjs +++ b/src/atom/commands.pegjs @@ -2,6 +2,7 @@ var Substitution = require('command-interpreter/substitution'); var LineAddress = require('command-interpreter/line-address'); var AddressRange = require('command-interpreter/address-range'); + var EofAddress = require('command-interpreter/eof-address'); } start @@ -19,6 +20,7 @@ addressRange primitiveAddress = lineNumber:integer { return new LineAddress(lineNumber) } + / '$' { return new EofAddress() } substitution = "s" _ "/" find:pattern "/" replace:pattern "/" _ options:[g]* { diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index f445513eb..cbc2fd559 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -341,7 +341,6 @@ class Editor extends View @lineHeight = fragment.outerHeight() fragment.remove() - getCursor: -> @cursor moveCursorUp: -> @cursor.moveUp() moveCursorDown: -> @cursor.moveDown() @@ -373,6 +372,8 @@ class Editor extends View setText: (text) -> @buffer.setText(text) getText: -> @buffer.getText() + getLastBufferRow: -> @buffer.lastRow() + getBufferLineLength: (row) -> @buffer.getLineLength(row) insertText: (text) -> { text, shouldOutdent } = @autoIndentText(text)