Add $ address to command interpreter

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-03-22 11:38:48 -07:00
parent d5479a0b60
commit 296a80160b
6 changed files with 24 additions and 4 deletions

View File

@ -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]])

View File

@ -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)

View File

@ -1,4 +1,4 @@
module.exports =
class Address
execute: (editor) ->
editor.getSelection().setBufferRange(@getRange())
editor.getSelection().setBufferRange(@getRange(editor))

View File

@ -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])

View File

@ -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]* {

View File

@ -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)