mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Add methods to be symmetrical with selections
* getCursorsOrderedByBufferPosition * getCursorBufferPositions * getCursorScreenPositions
This commit is contained in:
parent
e74244fc25
commit
7ca5ece68a
@ -750,6 +750,26 @@ describe "Editor", ->
|
||||
buffer.insert([8, 0], '...')
|
||||
expect(cursorMovedHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "::getCursorBufferPositions()", ->
|
||||
it "returns the existing cursor", ->
|
||||
cursor1 = editor.addCursorAtBufferPosition([8, 5])
|
||||
cursor2 = editor.addCursorAtBufferPosition([4, 5])
|
||||
expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [4, 5], [8, 5]]
|
||||
|
||||
describe "::getCursorScreenPositions()", ->
|
||||
it "returns the existing cursor", ->
|
||||
editor.foldBufferRow(4)
|
||||
cursor1 = editor.addCursorAtBufferPosition([8, 5])
|
||||
cursor2 = editor.addCursorAtBufferPosition([3, 5])
|
||||
expect(editor.getCursorScreenPositions()).toEqual [[0, 0], [3, 5], [5, 5]]
|
||||
|
||||
describe "::getCursorsOrderedByBufferPosition()", ->
|
||||
it "returns all cursors ordered by buffer positions", ->
|
||||
originalCursor = editor.getCursor()
|
||||
cursor1 = editor.addCursorAtBufferPosition([8, 5])
|
||||
cursor2 = editor.addCursorAtBufferPosition([4, 5])
|
||||
expect(editor.getCursorsOrderedByBufferPosition()).toEqual [originalCursor, cursor2, cursor1]
|
||||
|
||||
describe "addCursorAtScreenPosition(screenPosition)", ->
|
||||
describe "when a cursor already exists at the position", ->
|
||||
it "returns the existing cursor", ->
|
||||
|
@ -569,3 +569,11 @@ class Cursor extends Model
|
||||
false
|
||||
else
|
||||
bufferPosition.column > firstCharacterColumn
|
||||
|
||||
# Public: Compare this cursor's buffer position to another cursor's buffer position.
|
||||
#
|
||||
# See {Point::compare} for more details.
|
||||
#
|
||||
# * `otherCursor`{Cursor} to compare against
|
||||
compare: (otherCursor) ->
|
||||
@getBufferPosition().compare(otherCursor.getBufferPosition())
|
||||
|
@ -1513,10 +1513,16 @@ class Editor extends Model
|
||||
# Essential: Get the position of the most recently added cursor in buffer
|
||||
# coordinates.
|
||||
#
|
||||
# Returns a {Point}.
|
||||
# Returns a {Point}
|
||||
getCursorBufferPosition: ->
|
||||
@getCursor().getBufferPosition()
|
||||
|
||||
# Essential: Get the position of all the cursor positions in buffer coordinates.
|
||||
#
|
||||
# Returns {Array} of {Point}s
|
||||
getCursorBufferPositions: ->
|
||||
cursor.getBufferPosition() for cursor in @getCursorsOrderedByBufferPosition()
|
||||
|
||||
# Essential: Move the cursor to the given position in buffer coordinates.
|
||||
#
|
||||
# If there are multiple cursors, they will be consolidated to a single cursor.
|
||||
@ -1535,6 +1541,12 @@ class Editor extends Model
|
||||
getCursorScreenPosition: ->
|
||||
@getCursor().getScreenPosition()
|
||||
|
||||
# Essential: Get the position of all the cursor positions in screen coordinates.
|
||||
#
|
||||
# Returns {Array} of {Point}s
|
||||
getCursorScreenPositions: ->
|
||||
cursor.getScreenPosition() for cursor in @getCursorsOrderedByBufferPosition()
|
||||
|
||||
# Get the row of the most recently added cursor in screen coordinates.
|
||||
#
|
||||
# Returns the screen row {Number}.
|
||||
@ -1717,13 +1729,20 @@ class Editor extends Model
|
||||
getWordUnderCursor: (options) ->
|
||||
@getTextInBufferRange(@getCursor().getCurrentWordBufferRange(options))
|
||||
|
||||
# Extended: Get an Array of all {Cursor}s.
|
||||
getCursors: -> new Array(@cursors...)
|
||||
|
||||
# Extended: Get the most recently added {Cursor}.
|
||||
getCursor: ->
|
||||
_.last(@cursors)
|
||||
|
||||
# Extended: Get an Array of all {Cursor}s.
|
||||
getCursors: -> new Array(@cursors...)
|
||||
|
||||
# Extended: Get all {Cursors}s, ordered by their position in the buffer
|
||||
# instead of the order in which they were added.
|
||||
#
|
||||
# Returns an {Array} of {Selection}s.
|
||||
getCursorsOrderedByBufferPosition: ->
|
||||
@getCursors().sort (a, b) -> a.compare(b)
|
||||
|
||||
# Add a cursor based on the given {DisplayBufferMarker}.
|
||||
addCursor: (marker) ->
|
||||
cursor = new Cursor(editor: this, marker: marker)
|
||||
|
Loading…
Reference in New Issue
Block a user