mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
Add basic top/bottom cursor/selection commands
This commit is contained in:
parent
cce1218fda
commit
c6d7aaf39c
@ -196,6 +196,22 @@ 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 ".setCursorScreenPosition({row, column})", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
@ -783,6 +799,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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
6
src/atom/keybindings/apple.coffee
Normal file
6
src/atom/keybindings/apple.coffee
Normal 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'
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user