Add basic top/bottom cursor/selection commands

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-28 13:51:02 -07:00
parent cce1218fda
commit c6d7aaf39c
7 changed files with 80 additions and 0 deletions

View File

@@ -60,6 +60,12 @@ class CompositeCursor
moveToNextWord: ->
@modifyCursors (cursor) -> cursor.moveToNextWord()
moveToTop: ->
@modifyCursors (cursor) -> cursor.moveToTop()
moveToBottom: ->
@modifyCursors (cursor) -> cursor.moveToBottom()
handleBufferChange: (e) ->
@modifyCursors (cursor) -> cursor.handleBufferChange(e)

View File

@@ -79,6 +79,14 @@ class CompositeSeleciton
selection.selectDown() for selection in @getSelections()
@mergeIntersectingSelections()
selectToTop: ->
selection.selectToTop() for selection in @getSelections()
@mergeIntersectingSelections reverse: true
selectToBottom: ->
selection.selectToBottom() for selection in @getSelections()
@mergeIntersectingSelections()
setBufferRange: (bufferRange, options) ->
@getLastSelection().setBufferRange(bufferRange, options)

View File

@@ -139,6 +139,12 @@ class Cursor extends View
@setScreenPosition({row, column})
moveToTop: ->
@setBufferPosition [0,0]
moveToBottom: ->
@setBufferPosition @editor.getEofPosition()
moveLeftUntilMatch: (regex) ->
row = @getScreenRow()
column = @getScreenColumn()

View File

@@ -42,6 +42,7 @@ class Editor extends View
requireStylesheet 'editor.css'
requireStylesheet 'theme/twilight.css'
require 'keybindings/emacs'
require 'keybindings/apple'
@id = Editor.idCounter++
@editSessionsByBufferId = {}
@@ -103,6 +104,11 @@ class Editor extends View
@on 'split-down', => @splitDown()
@on 'close', => @remove(); false
@on 'move-to-top', => @moveCursorToTop()
@on 'select-to-top', => @selectToTop()
@on 'move-to-bottom', => @moveCursorToBottom()
@on 'select-to-bottom', => @selectToBottom()
buildCursorAndSelection: ->
@compositeSelection = new CompositeSelection(this)
@compositeCursor = new CompositeCursor(this)
@@ -357,6 +363,8 @@ class Editor extends View
moveCursorRight: -> @compositeCursor.moveRight()
moveCursorLeft: -> @compositeCursor.moveLeft()
moveCursorToNextWord: -> @compositeCursor.moveToNextWord()
moveCursorToTop: -> @compositeCursor.moveToTop()
moveCursorToBottom: -> @compositeCursor.moveToBottom()
setCursorScreenPosition: (position) -> @compositeCursor.setScreenPosition(position)
getCursorScreenPosition: -> @compositeCursor.getCursor().getScreenPosition()
setCursorBufferPosition: (position) -> @compositeCursor.setBufferPosition(position)
@@ -372,6 +380,8 @@ class Editor extends View
selectLeft: -> @compositeSelection.selectLeft()
selectUp: -> @compositeSelection.selectUp()
selectDown: -> @compositeSelection.selectDown()
selectToTop: -> @compositeSelection.selectToTop()
selectToBottom: -> @compositeSelection.selectToBottom()
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
clearSelections: -> @compositeSelection.clearSelections()

View File

@@ -0,0 +1,6 @@
window.keymap.bindKeys '.editor'
'meta-up': 'move-to-top'
'meta-shift-up': 'select-to-top'
'meta-down': 'move-to-bottom'
'meta-shift-down': 'select-to-bottom'
'alt-up': 'move-to-start-of-paragraph'

View File

@@ -212,6 +212,14 @@ class Selection extends View
@modifySelection =>
@cursor.moveDown()
selectToTop: ->
@modifySelection =>
@cursor.moveToTop()
selectToBottom: ->
@modifySelection =>
@cursor.moveToBottom()
selectLeftUntilMatch: (regex) ->
@modifySelection =>
@cursor.moveLeftUntilMatch(regex)