Merge branch 'master' of github.com:github/atom

This commit is contained in:
Nathan Sobo
2012-03-28 14:20:54 -07:00
7 changed files with 113 additions and 9 deletions

View File

@@ -176,7 +176,6 @@ describe "Editor", ->
editor.setMaxLineLength(50)
fold = editor.createFold([[3, 52], [3, 56]])
fold.destroy()
# console.log editor.renderer.bufferRowsForScreenRows()
expect(editor.gutter.find('.line-number:last').text()).toBe '13'
it "adds a drop shadow when the horizontal scroller is scrolled to the right", ->
@@ -196,6 +195,42 @@ describe "Editor", ->
expect(editor.gutter).not.toHaveClass('drop-shadow')
describe "cursor movement", ->
describe "move-to-top ", ->
it "moves cusor to the top of the buffer", ->
editor.setCursorScreenPosition [11,1]
editor.addCursorAtScreenPosition [12,0]
editor.trigger 'move-to-top'
expect(editor.getCursors().length).toBe 1
expect(editor.getCursorBufferPosition()).toEqual [0,0]
describe "move-to-bottom", ->
it "moves cusor to the bottom of the buffer", ->
editor.setCursorScreenPosition [0,0]
editor.addCursorAtScreenPosition [1,0]
editor.trigger 'move-to-bottom'
expect(editor.getCursors().length).toBe 1
expect(editor.getCursorBufferPosition()).toEqual [12,2]
describe "move-to-beginning-of-line", ->
it "moves cursor to the beginning of line", ->
editor.setCursorScreenPosition [0,5]
editor.addCursorAtScreenPosition [1,7]
editor.trigger 'move-to-beginning-of-line'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,0]
expect(cursor2.getBufferPosition()).toEqual [1,0]
describe "move-to-end-of-line", ->
it "moves cursor to the end of line", ->
editor.setCursorScreenPosition [0,0]
editor.addCursorAtScreenPosition [1,0]
editor.trigger 'move-to-end-of-line'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,29]
expect(cursor2.getBufferPosition()).toEqual [1,30]
describe ".setCursorScreenPosition({row, column})", ->
beforeEach ->
editor.attachToDom()
@@ -783,6 +818,26 @@ describe "Editor", ->
expect(range.end).toEqual({row: 5, column: 27})
expect(editor.getCursorScreenPosition()).toEqual(row: 5, column: 27)
describe "select-to-top", ->
it "selects text from cusor position to the top of the buffer", ->
editor.setCursorScreenPosition [11,2]
editor.addCursorAtScreenPosition [10,0]
editor.trigger 'select-to-top'
expect(editor.getCursors().length).toBe 1
expect(editor.getCursorBufferPosition()).toEqual [0,0]
expect(editor.getSelection().getBufferRange()).toEqual [[0,0], [11,2]]
expect(editor.getSelection().isReversed()).toBeTruthy()
describe "select-to-bottom", ->
it "selects text from cusor position to the bottom of the buffer", ->
editor.setCursorScreenPosition [10,0]
editor.addCursorAtScreenPosition [9,3]
editor.trigger 'select-to-bottom'
expect(editor.getCursors().length).toBe 1
expect(editor.getCursorBufferPosition()).toEqual [12,2]
expect(editor.getSelection().getBufferRange()).toEqual [[9,3], [12,2]]
expect(editor.getSelection().isReversed()).toBeFalsy()
describe "multiple cursors", ->
it "places multiple cursor with meta-click", ->
editor.attachToDom()

View File

@@ -60,6 +60,18 @@ class CompositeCursor
moveToNextWord: ->
@modifyCursors (cursor) -> cursor.moveToNextWord()
moveToTop: ->
@modifyCursors (cursor) -> cursor.moveToTop()
moveToBottom: ->
@modifyCursors (cursor) -> cursor.moveToBottom()
moveToBeginningOfLine: ->
@modifyCursors (cursor) -> cursor.moveToBeginningOfLine()
moveToEndOfLine: ->
@modifyCursors (cursor) -> cursor.moveToEndOfLine()
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

@@ -116,11 +116,11 @@ class Cursor extends View
@setBufferPosition(nextPosition or @editor.getEofPosition())
moveToLineEnd: ->
moveToEndOfLine: ->
{ row } = @getBufferPosition()
@setBufferPosition({ row, column: @editor.buffer.lineForRow(row).length })
moveToLineStart: ->
moveToBeginningOfLine: ->
{ row } = @getScreenPosition()
@setScreenPosition({ row, column: 0 })
@@ -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,13 @@ 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()
@on 'move-to-beginning-of-line', => @moveCursorToBeginningOfLine()
@on 'move-to-end-of-line', => @moveCursorToEndOfLine()
buildCursorAndSelection: ->
@compositeSelection = new CompositeSelection(this)
@compositeCursor = new CompositeCursor(this)
@@ -357,6 +365,10 @@ class Editor extends View
moveCursorRight: -> @compositeCursor.moveRight()
moveCursorLeft: -> @compositeCursor.moveLeft()
moveCursorToNextWord: -> @compositeCursor.moveToNextWord()
moveCursorToTop: -> @compositeCursor.moveToTop()
moveCursorToBottom: -> @compositeCursor.moveToBottom()
moveCursorToBeginningOfLine: -> @compositeCursor.moveToBeginningOfLine()
moveCursorToEndOfLine: -> @compositeCursor.moveToEndOfLine()
setCursorScreenPosition: (position) -> @compositeCursor.setScreenPosition(position)
getCursorScreenPosition: -> @compositeCursor.getCursor().getScreenPosition()
setCursorBufferPosition: (position) -> @compositeCursor.setBufferPosition(position)
@@ -372,6 +384,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,7 @@
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'
'meta-right': 'move-to-end-of-line'
'meta-left': 'move-to-beginning-of-line'

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)
@@ -220,12 +228,6 @@ class Selection extends View
@modifySelection =>
@cursor.setScreenPosition(position)
moveCursorToLineEnd: ->
@cursor.moveToLineEnd()
moveCursorToLineStart: ->
@cursor.moveToLineStart()
cut: (maintainPasteboard=false) ->
@copy(maintainPasteboard)
@delete()