mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge branch 'sam'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
EventEmitter = require 'event-emitter'
|
||||
UndoManager = require 'undo-manager'
|
||||
@@ -59,6 +60,21 @@ class Buffer
|
||||
lastLine: ->
|
||||
@lineForRow(@lastRow())
|
||||
|
||||
characterIndexForPosition: (position) ->
|
||||
position = Point.fromObject(position)
|
||||
|
||||
index = 0
|
||||
index += @getLineLength(row) + 1 for row in [0...position.row]
|
||||
index + position.column
|
||||
|
||||
positionForCharacterIndex: (index) ->
|
||||
row = 0
|
||||
while index >= (lineLength = @getLineLength(row) + 1)
|
||||
index -= lineLength
|
||||
row++
|
||||
|
||||
new Point(row, index)
|
||||
|
||||
deleteRow: (row) ->
|
||||
range = null
|
||||
if row == @lastRow()
|
||||
|
||||
12
src/atom/command-interpreter.coffee
Normal file
12
src/atom/command-interpreter.coffee
Normal file
@@ -0,0 +1,12 @@
|
||||
fs = require 'fs'
|
||||
PEG = require 'pegjs'
|
||||
|
||||
module.exports =
|
||||
class CommandInterpreter
|
||||
constructor: (@editor) ->
|
||||
@parser = PEG.buildParser(fs.read(require.resolve 'commands.pegjs'))
|
||||
|
||||
eval: (command) ->
|
||||
operation = @parser.parse(command)
|
||||
operation.perform(@editor)
|
||||
|
||||
20
src/atom/command-interpreter/substitution.coffee
Normal file
20
src/atom/command-interpreter/substitution.coffee
Normal file
@@ -0,0 +1,20 @@
|
||||
module.exports =
|
||||
class Substitution
|
||||
constructor: (@findText, @replaceText) ->
|
||||
@findRegex = new RegExp(@findText)
|
||||
|
||||
perform: (editor) ->
|
||||
{ buffer } = editor
|
||||
selectedText = editor.getSelectedText()
|
||||
|
||||
selectionStartIndex = buffer.characterIndexForPosition(editor.getSelection().getBufferRange().start)
|
||||
|
||||
match = @findRegex.exec(selectedText)
|
||||
matchStartIndex = selectionStartIndex + match.index
|
||||
matchEndIndex = matchStartIndex + match[0].length
|
||||
|
||||
startPosition = buffer.positionForCharacterIndex(matchStartIndex)
|
||||
endPosition = buffer.positionForCharacterIndex(matchEndIndex)
|
||||
|
||||
buffer.change([startPosition, endPosition], @replaceText)
|
||||
|
||||
8
src/atom/commands.pegjs
Normal file
8
src/atom/commands.pegjs
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
var Substitution = require('command-interpreter/substitution');
|
||||
}
|
||||
|
||||
substitution
|
||||
= "s" _ "/" find:([^/]*) "/" replace:([^/]*) "/" { return new Substitution(find.join(''), replace.join('')) }
|
||||
|
||||
_ = " "*
|
||||
@@ -61,6 +61,7 @@ class LineMap
|
||||
@translatePosition('screenDelta', 'bufferDelta', screenPosition)
|
||||
|
||||
screenRangeForBufferRange: (bufferRange) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
start = @screenPositionForBufferPosition(bufferRange.start)
|
||||
end = @screenPositionForBufferPosition(bufferRange.end)
|
||||
new Range(start, end)
|
||||
|
||||
Reference in New Issue
Block a user