mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 16:09:57 +03:00
Add $ address to command interpreter
This commit is contained in:
parent
d5479a0b60
commit
296a80160b
@ -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]])
|
||||||
|
@ -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)
|
||||||
|
@ -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))
|
||||||
|
9
src/atom/command-interpreter/eof-address.coffee
Normal file
9
src/atom/command-interpreter/eof-address.coffee
Normal 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])
|
@ -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]* {
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user