mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Remove methods from CompositeCursor + more 💄
This commit is contained in:
@@ -12,7 +12,7 @@ describe "Cursor", ->
|
||||
editor = new Editor
|
||||
editor.enableKeymap()
|
||||
editor.setBuffer(buffer)
|
||||
cursor = editor.getCursors()[0]
|
||||
cursor = editor.getCursorView()
|
||||
|
||||
describe "adding and removing of the idle class", ->
|
||||
it "removes the idle class while moving, then adds it back when it stops", ->
|
||||
|
||||
@@ -877,7 +877,7 @@ describe "Editor", ->
|
||||
expect(editor.css('font-size')).toBe '30px'
|
||||
expect(editor.lineHeight).toBeGreaterThan lineHeightBefore
|
||||
expect(editor.charWidth).toBeGreaterThan charWidthBefore
|
||||
expect(editor.getCursors()[0].position()).toEqual { top: 5 * editor.lineHeight, left: 5 * editor.charWidth }
|
||||
expect(editor.getCursorView().position()).toEqual { top: 5 * editor.lineHeight, left: 5 * editor.charWidth }
|
||||
|
||||
# ensure we clean up font size subscription
|
||||
editor.trigger('close')
|
||||
@@ -1698,7 +1698,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(5)).toBe ", left = [], right = [];"
|
||||
expect(editor.lineForBufferRow(6)).toBe " while(items.length > 0) {"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [4, 0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [5, 0]
|
||||
|
||||
@@ -1712,7 +1712,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(3)).toBe "abc var pivot = items.shift(), current, left = [], right = [];"
|
||||
expect(editor.lineForBufferRow(6)).toBe "abc current < pivot ? left.push(current) : right.push(current);"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3,3]
|
||||
expect(cursor2.getBufferPosition()).toEqual [6,3]
|
||||
|
||||
@@ -1730,7 +1730,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(8)).toBe " current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(editor.lineForBufferRow(9)).toBe " }"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [4,0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [8,0]
|
||||
|
||||
@@ -1743,7 +1743,7 @@ describe "Editor", ->
|
||||
it "replaces each selection range with the inserted characters", ->
|
||||
editor.insertText("x")
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
|
||||
expect(cursor1.getScreenPosition()).toEqual [0, 5]
|
||||
@@ -1757,7 +1757,7 @@ describe "Editor", ->
|
||||
it "replaces all selected ranges with newlines", ->
|
||||
editor.insertText("\n")
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
|
||||
expect(cursor1.getScreenPosition()).toEqual [1, 0]
|
||||
@@ -1779,7 +1779,7 @@ describe "Editor", ->
|
||||
|
||||
expect(editor.lineForBufferRow(3)).toBe " var pivo = items.shift(), curren, left = [], right = [];"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3, 12]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3, 36]
|
||||
|
||||
@@ -1797,7 +1797,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(3)).toBe " var pivo = items.shift(), current, left = [], right = [];"
|
||||
expect(editor.lineForBufferRow(4)).toBe " whileitems.length > 0) {"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3, 12]
|
||||
expect(cursor2.getBufferPosition()).toEqual [4, 9]
|
||||
|
||||
@@ -1816,7 +1816,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(4)).toBe " current = items.shift(); current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(editor.lineForBufferRow(5)).toBe " }"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [2,40]
|
||||
expect(cursor2.getBufferPosition()).toEqual [4,30]
|
||||
|
||||
@@ -1839,7 +1839,7 @@ describe "Editor", ->
|
||||
|
||||
expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current left = [], right = [];"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3, 13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3, 37]
|
||||
|
||||
@@ -1857,7 +1857,7 @@ describe "Editor", ->
|
||||
expect(editor.lineForBufferRow(3)).toBe " var pivot= items.shift(), current, left = [], right = [];"
|
||||
expect(editor.lineForBufferRow(4)).toBe " while(tems.length > 0) {"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3, 13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [4, 10]
|
||||
|
||||
@@ -1874,7 +1874,7 @@ describe "Editor", ->
|
||||
|
||||
expect(editor.lineForBufferRow(0)).toBe "var quicksort = function () { var sort = function(items) { if (items.length <= 1) return items;"
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,29]
|
||||
expect(cursor2.getBufferPosition()).toEqual [0,59]
|
||||
|
||||
@@ -1892,7 +1892,7 @@ describe "Editor", ->
|
||||
editor.setCursorScreenPosition([3, 13])
|
||||
editor.addCursorAtScreenPosition([3, 38])
|
||||
editor.addCursorAtScreenPosition([4, 1])
|
||||
[cursor1, cursor2, cursor3] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2, cursor3] = editor.getCursors()
|
||||
|
||||
editor.moveCursorLeft()
|
||||
expect(cursor1.getBufferPosition()).toEqual [3, 12]
|
||||
@@ -2033,14 +2033,13 @@ describe "Editor", ->
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
editor.addCursorAtScreenPosition([1, 1])
|
||||
|
||||
[cursor1, cursor2, cursor3] = editor.compositeCursor.getCursors()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 3
|
||||
[cursor1, cursor2, cursor3] = editor.getCursors()
|
||||
expect(editor.getCursors().length).toBe 3
|
||||
|
||||
editor.backspace()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 2
|
||||
expect(editor.getCursors()).toEqual [cursor1, cursor3]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor3.getBufferPosition()).toEqual [1,0]
|
||||
expect(cursor2.parent().length).toBe 0
|
||||
|
||||
editor.insertText "x"
|
||||
expect(editor.lineForBufferRow(0)).toBe "xar quicksort = function () {"
|
||||
@@ -2050,35 +2049,31 @@ describe "Editor", ->
|
||||
editor.setCursorScreenPosition([0, 0])
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
editor.moveCursorLeft()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 1
|
||||
expect(cursor2.parent()).not.toExist()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
editor.addCursorAtScreenPosition([1, 0])
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 1
|
||||
expect(cursor2.parent()).not.toExist()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
editor.setCursorScreenPosition([12, 2])
|
||||
editor.addCursorAtScreenPosition([12, 1])
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorRight()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 1
|
||||
expect(cursor2.parent()).not.toExist()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
editor.addCursorAtScreenPosition([11, 2])
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 1
|
||||
expect(cursor2.parent()).not.toExist()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
it "merges cursors when the mouse is clicked without the meta-key", ->
|
||||
@@ -2086,10 +2081,10 @@ describe "Editor", ->
|
||||
editor.setCursorScreenPosition([0, 0])
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
|
||||
[cursor1, cursor2] = editor.compositeCursor.getCursors()
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [4, 7])
|
||||
expect(editor.compositeCursor.getCursors().length).toBe 1
|
||||
expect(cursor2.parent()).not.toExist()
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [4, 7]
|
||||
|
||||
editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [5, 27])
|
||||
|
||||
@@ -6,14 +6,11 @@ class CompositeCursor
|
||||
constructor: (@editor) ->
|
||||
@cursors = []
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@moveCursors (cursor) -> cursor.handleBufferChange(e)
|
||||
|
||||
getCursor: (index) ->
|
||||
getCursorView: (index) ->
|
||||
index ?= @cursors.length - 1
|
||||
@cursors[index]
|
||||
|
||||
getCursors: ->
|
||||
getCursorViews: ->
|
||||
@cursors
|
||||
|
||||
addCursorView: (cursor) ->
|
||||
@@ -26,69 +23,11 @@ class CompositeCursor
|
||||
for view in @getCursors()
|
||||
return view if view.cursor == cursor
|
||||
|
||||
removeAllCursors: ->
|
||||
cursor.remove() for cursor in @getCursors()
|
||||
removeAllCursorViews: ->
|
||||
cursor.remove() for cursor in @getCursorViews()
|
||||
|
||||
removeCursor: (cursor) ->
|
||||
_.remove(@cursors, cursor)
|
||||
|
||||
updateAppearance: ->
|
||||
cursor.updateAppearance() for cursor in @cursors
|
||||
|
||||
moveCursors: (fn) ->
|
||||
fn(cursor) for cursor in @cursors
|
||||
@mergeCursors()
|
||||
|
||||
setScreenPosition: (screenPosition) ->
|
||||
@moveCursors (cursor) -> cursor.setScreenPosition(screenPosition)
|
||||
|
||||
setBufferPosition: (bufferPosition) ->
|
||||
@moveCursors (cursor) -> cursor.setBufferPosition(bufferPosition)
|
||||
|
||||
updateBufferPosition: ->
|
||||
@moveCursors (cursor) -> cursor.setBufferPosition(cursor.getBufferPosition())
|
||||
|
||||
moveLeft: ->
|
||||
@moveCursors (cursor) -> cursor.moveLeft()
|
||||
|
||||
moveRight: ->
|
||||
@moveCursors (cursor) -> cursor.moveRight()
|
||||
|
||||
moveUp: ->
|
||||
@moveCursors (cursor) -> cursor.moveUp()
|
||||
|
||||
moveDown: ->
|
||||
@moveCursors (cursor) -> cursor.moveDown()
|
||||
|
||||
moveToNextWord: ->
|
||||
@moveCursors (cursor) -> cursor.moveToNextWord()
|
||||
|
||||
moveToBeginningOfWord: ->
|
||||
@moveCursors (cursor) -> cursor.moveToBeginningOfWord()
|
||||
|
||||
moveToEndOfWord: ->
|
||||
@moveCursors (cursor) -> cursor.moveToEndOfWord()
|
||||
|
||||
moveToTop: ->
|
||||
@moveCursors (cursor) -> cursor.moveToTop()
|
||||
|
||||
moveToBottom: ->
|
||||
@moveCursors (cursor) -> cursor.moveToBottom()
|
||||
|
||||
moveToBeginningOfLine: ->
|
||||
@moveCursors (cursor) -> cursor.moveToBeginningOfLine()
|
||||
|
||||
moveToEndOfLine: ->
|
||||
@moveCursors (cursor) -> cursor.moveToEndOfLine()
|
||||
|
||||
moveToFirstCharacterOfLine: ->
|
||||
@moveCursors (cursor) -> cursor.moveToFirstCharacterOfLine()
|
||||
|
||||
mergeCursors: ->
|
||||
positions = []
|
||||
for cursor in new Array(@cursors...)
|
||||
position = cursor.getBufferPosition().toString()
|
||||
if position in positions
|
||||
cursor.remove()
|
||||
else
|
||||
positions.push(position)
|
||||
|
||||
@@ -37,7 +37,7 @@ class CursorView extends View
|
||||
pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition)
|
||||
@css(pixelPosition)
|
||||
|
||||
if this == _.last(@editor.getCursors())
|
||||
if @cursor == @editor.getLastCursor()
|
||||
@editor.scrollTo(pixelPosition)
|
||||
|
||||
if @editor.isFoldedAtScreenRow(screenPosition.row)
|
||||
|
||||
@@ -357,7 +357,7 @@ class Editor extends View
|
||||
|
||||
if @activeEditSession
|
||||
@saveActiveEditSession()
|
||||
@compositeCursor.removeAllCursors()
|
||||
@removeAllCursorViews()
|
||||
@activeEditSession.off()
|
||||
|
||||
@activeEditSession = @editSessions[index]
|
||||
@@ -650,7 +650,11 @@ class Editor extends View
|
||||
@compositeCursor.updateAppearance()
|
||||
@updateRenderedLines()
|
||||
|
||||
getCursors: -> @compositeCursor.getCursors()
|
||||
getCursorView: (index) -> @compositeCursor.getCursorView(index)
|
||||
getCursorViews: -> @compositeCursor.getCursorViews()
|
||||
removeAllCursorViews: -> @compositeCursor.removeAllCursorViews()
|
||||
getCursors: -> @activeEditSession.getCursors()
|
||||
getLastCursor: -> @activeEditSession.getLastCursor()
|
||||
moveCursorUp: -> @activeEditSession.moveCursorUp()
|
||||
moveCursorDown: -> @activeEditSession.moveCursorDown()
|
||||
moveCursorLeft: -> @activeEditSession.moveCursorLeft()
|
||||
@@ -826,8 +830,8 @@ class Editor extends View
|
||||
@scrollView.scrollLeft(desiredLeft)
|
||||
|
||||
syncCursorAnimations: ->
|
||||
for cursor in @getCursors()
|
||||
do (cursor) -> cursor.resetCursorAnimation()
|
||||
for cursorView in @getCursorViews()
|
||||
do (cursorView) -> cursorView.resetCursorAnimation()
|
||||
|
||||
foldAll: ->
|
||||
@renderer.foldAll()
|
||||
|
||||
Reference in New Issue
Block a user