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') interpreter.eval(editor, '4,7')
expect(editor.selection.getBufferRange()).toEqual [[3, 0], [7, 0]] 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", -> describe "substitution", ->
it "does nothing if there are no matches", -> it "does nothing if there are no matches", ->
editor.selection.setBufferRange([[6, 0], [6, 44]]) editor.selection.setBufferRange([[6, 0], [6, 44]])

View File

@ -5,5 +5,5 @@ module.exports =
class AddressRange extends Address class AddressRange extends Address
constructor: (@startAddress, @endAddress) -> constructor: (@startAddress, @endAddress) ->
getRange: -> getRange: (editor) ->
new Range(@startAddress.getRange().start, @endAddress.getRange().end) new Range(@startAddress.getRange(editor).start, @endAddress.getRange(editor).end)

View File

@ -1,4 +1,4 @@
module.exports = module.exports =
class Address class Address
execute: (editor) -> 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 Substitution = require('command-interpreter/substitution');
var LineAddress = require('command-interpreter/line-address'); var LineAddress = require('command-interpreter/line-address');
var AddressRange = require('command-interpreter/address-range'); var AddressRange = require('command-interpreter/address-range');
var EofAddress = require('command-interpreter/eof-address');
} }
start start
@ -19,6 +20,7 @@ addressRange
primitiveAddress primitiveAddress
= lineNumber:integer { return new LineAddress(lineNumber) } = lineNumber:integer { return new LineAddress(lineNumber) }
/ '$' { return new EofAddress() }
substitution substitution
= "s" _ "/" find:pattern "/" replace:pattern "/" _ options:[g]* { = "s" _ "/" find:pattern "/" replace:pattern "/" _ options:[g]* {

View File

@ -341,7 +341,6 @@ class Editor extends View
@lineHeight = fragment.outerHeight() @lineHeight = fragment.outerHeight()
fragment.remove() fragment.remove()
getCursor: -> @cursor getCursor: -> @cursor
moveCursorUp: -> @cursor.moveUp() moveCursorUp: -> @cursor.moveUp()
moveCursorDown: -> @cursor.moveDown() moveCursorDown: -> @cursor.moveDown()
@ -373,6 +372,8 @@ class Editor extends View
setText: (text) -> @buffer.setText(text) setText: (text) -> @buffer.setText(text)
getText: -> @buffer.getText() getText: -> @buffer.getText()
getLastBufferRow: -> @buffer.lastRow()
getBufferLineLength: (row) -> @buffer.getLineLength(row)
insertText: (text) -> insertText: (text) ->
{ text, shouldOutdent } = @autoIndentText(text) { text, shouldOutdent } = @autoIndentText(text)