Rename App.coffee to Atom.coffee. This also required moving src/atom,spec/atom to src/app,spec/app

This commit is contained in:
Corey Johnson
2012-04-03 10:33:08 -07:00
parent e0274c293f
commit 1efb712fd3
73 changed files with 15 additions and 14 deletions

View File

@@ -0,0 +1,10 @@
class Command
constructor: (@editor) ->
isComplete: -> true
class DeleteRight extends Command
execute: ->
@editor.delete() unless @editor.getCurrentBufferLine().length == 0
module.exports = { DeleteRight }

View File

@@ -0,0 +1,89 @@
Point = require 'point'
getWordRegex = -> /(\w+)|([^\w\s]+)/g
class Motion
constructor: (@editor) ->
isComplete: -> true
class MoveLeft extends Motion
execute: ->
{column, row} = @editor.getCursorScreenPosition()
@editor.moveCursorLeft() if column > 0
select: ->
position = @editor.getCursorScreenPosition().copy()
position.column-- if position.column > 0
@editor.selectToBufferPosition(position)
class MoveRight extends Motion
execute: ->
{column, row} = @editor.getCursorScreenPosition()
@editor.moveCursorRight()
class MoveUp extends Motion
execute: ->
{column, row} = @editor.getCursorScreenPosition()
@editor.moveCursorUp() if row > 0
class MoveDown extends Motion
execute: ->
{column, row} = @editor.getCursorScreenPosition()
@editor.moveCursorDown() if row < (@editor.buffer.numLines() - 1)
class MoveToPreviousWord extends Motion
execute: ->
@editor.getCursor().moveToBeginningOfWord()
select: ->
@editor.getSelection().selectToBeginningOfWord()
class MoveToNextWord extends Motion
execute: ->
@editor.setCursorScreenPosition(@nextWordPosition())
select: ->
@editor.selectToBufferPosition(@nextWordPosition())
nextWordPosition: ->
regex = getWordRegex()
{ row, column } = @editor.getCursorScreenPosition()
rightOfCursor = @editor.buffer.lineForRow(row).substring(column)
match = regex.exec(rightOfCursor)
# If we're on top of part of a word, match the next one.
match = regex.exec(rightOfCursor) if match?.index is 0
if match
column += match.index
else if row + 1 == @editor.buffer.numLines()
column = @editor.buffer.lineForRow(row).length
else
nextLineMatch = regex.exec(@editor.buffer.lineForRow(++row))
column = nextLineMatch?.index or 0
{ row, column }
class MoveToNextParagraph extends Motion
execute: ->
@editor.setCursorScreenPosition(@nextPosition())
select: ->
@editor.selectToPosition(@nextPosition())
nextPosition: ->
regex = /[^\n]\n^$/gm
row = null
column = 0
startRow = @editor.getCursorBufferRow() + 1
for r in [startRow..@editor.buffer.getLastRow()]
if @editor.buffer.lineForRow(r).length == 0
row = r
break
if not row
row = @editor.buffer.getLastRow()
column = @editor.buffer.lastLine().length - 1
new Point(row, column)
module.exports = { Motion, MoveLeft, MoveRight, MoveUp, MoveDown, MoveToNextWord, MoveToPreviousWord, MoveToNextParagraph }

View File

@@ -0,0 +1,57 @@
_ = require 'underscore'
class OperatorError
constructor: (@message) ->
@name = "Operator Error"
class NumericPrefix
count: null
complete: null
operatorToRepeat: null
constructor: (@count) ->
@complete = false
isComplete: -> @complete
compose: (@operatorToRepeat) ->
@complete = true
if @operatorToRepeat.setCount?
@operatorToRepeat.setCount @count
@count = 1
addDigit: (digit) ->
@count = @count * 10 + digit
execute: ->
_.times @count, => @operatorToRepeat.execute()
select: ->
_.times @count, => @operatorToRepeat.select()
class Delete
motion: null
complete: null
constructor: (@editor) ->
@complete = false
isComplete: -> @complete
execute: ->
if @motion
@motion.select()
@editor.getSelection().delete()
else
@editor.buffer.deleteRow(@editor.getCursorBufferRow())
@editor.setCursorScreenPosition([@editor.getCursorScreenRow(), 0])
compose: (motion) ->
if not motion.select
throw new OperatorError("Delete must compose with a motion")
@motion = motion
@complete = true
module.exports = { NumericPrefix, Delete, OperatorError }