mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -1002,8 +1002,14 @@ describe "Editor", ->
|
||||
describe "multiple cursors", ->
|
||||
it "places multiple cursor with meta-click", ->
|
||||
editor.attachToDom()
|
||||
setEditorHeightInChars(editor, 5)
|
||||
editor.lines.trigger mousedownEvent(editor: editor, point: [3, 0])
|
||||
editor.scroller.scrollTop(editor.lineHeight * 6)
|
||||
|
||||
spyOn(editor, "scrollTo").andCallThrough()
|
||||
|
||||
editor.lines.trigger mousedownEvent(editor: editor, point: [6, 0], metaKey: true)
|
||||
expect(editor.scrollTo.callCount).toBe 1
|
||||
|
||||
[cursor1, cursor2] = editor.find('.cursor').map -> $(this).view()
|
||||
expect(cursor1.position()).toEqual(top: 3 * editor.lineHeight, left: 0)
|
||||
|
||||
@@ -6,10 +6,14 @@ class Anchor
|
||||
bufferPosition: null
|
||||
screenPosition: null
|
||||
|
||||
constructor: (editor) ->
|
||||
constructor: (editor, screenPosition) ->
|
||||
@editor = editor
|
||||
@bufferPosition = new Point(0, 0)
|
||||
@screenPosition = new Point(0, 0)
|
||||
|
||||
if screenPosition
|
||||
@setScreenPosition(screenPosition)
|
||||
else
|
||||
@bufferPosition = new Point(0,0)
|
||||
@screenPosition = new Point(0,0)
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
{ oldRange, newRange } = e
|
||||
|
||||
@@ -17,19 +17,18 @@ class CompositeCursor
|
||||
getCursors: ->
|
||||
@cursors
|
||||
|
||||
addCursor: ->
|
||||
cursor = new Cursor(@editor)
|
||||
addCursor: (screenPosition=null) ->
|
||||
cursor = new Cursor({@editor, screenPosition})
|
||||
@cursors.push(cursor)
|
||||
@editor.lines.append(cursor)
|
||||
cursor
|
||||
|
||||
addCursorAtScreenPosition: (screenPosition) ->
|
||||
cursor = @addCursor()
|
||||
cursor.setScreenPosition(screenPosition)
|
||||
cursor = @addCursor(screenPosition)
|
||||
|
||||
addCursorAtBufferPosition: (bufferPosition) ->
|
||||
cursor = @addCursor()
|
||||
cursor.setBufferPosition(bufferPosition)
|
||||
screenPosition = @editor.screenPositionForBufferPosition(bufferPosition)
|
||||
cursor = @addCursor(screenPosition)
|
||||
|
||||
removeCursor: (cursor) ->
|
||||
_.remove(@cursors, cursor)
|
||||
|
||||
@@ -12,10 +12,13 @@ class Cursor extends View
|
||||
editor: null
|
||||
wordRegex: /(\w+)|([^\w\s]+)/g
|
||||
|
||||
initialize: (@editor) ->
|
||||
@anchor = new Anchor(@editor)
|
||||
initialize: ({editor, screenPosition}) ->
|
||||
@editor = editor
|
||||
@anchor = new Anchor(@editor, screenPosition)
|
||||
@selection = @editor.compositeSelection.addSelectionForCursor(this)
|
||||
@one 'attach', => @updateAppearance()
|
||||
@one 'attach', =>
|
||||
@updateAppearance()
|
||||
@editor.syncCursorAnimations()
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@anchor.handleBufferChange(e)
|
||||
@@ -51,6 +54,11 @@ class Cursor extends View
|
||||
window.clearTimeout(@idleTimeout) if @idleTimeout
|
||||
@idleTimeout = window.setTimeout (=> @addClass 'idle'), 200
|
||||
|
||||
resetCursorAnimation: ->
|
||||
window.clearTimeout(@idleTimeout) if @idleTimeout
|
||||
@removeClass 'idle'
|
||||
_.defer => @addClass 'idle'
|
||||
|
||||
clearSelection: ->
|
||||
@selection.clearSelection() unless @selection.retainSelection
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ class Editor extends View
|
||||
@off 'mousemove', moveHandler
|
||||
reverse = @compositeSelection.getLastSelection().isReversed()
|
||||
@compositeSelection.mergeIntersectingSelections({reverse})
|
||||
@syncCursorAnimations()
|
||||
|
||||
renderLines: ->
|
||||
@lineCache = []
|
||||
@@ -484,9 +485,9 @@ class Editor extends View
|
||||
@buffer.getMode()
|
||||
|
||||
scrollTo: (pixelPosition) ->
|
||||
_.defer =>
|
||||
@scrollVertically(pixelPosition)
|
||||
@scrollHorizontally(pixelPosition)
|
||||
_.defer => # Optimization
|
||||
@scrollVertically(pixelPosition)
|
||||
@scrollHorizontally(pixelPosition)
|
||||
|
||||
scrollVertically: (pixelPosition) ->
|
||||
linesInView = @scroller.height() / @lineHeight
|
||||
@@ -516,5 +517,9 @@ class Editor extends View
|
||||
else if desiredLeft < @scroller.scrollLeft()
|
||||
@scroller.scrollLeft(desiredLeft)
|
||||
|
||||
syncCursorAnimations: ->
|
||||
for cursor in @getCursors()
|
||||
do (cursor) -> cursor.resetCursorAnimation()
|
||||
|
||||
logLines: ->
|
||||
@renderer.logLines()
|
||||
|
||||
Reference in New Issue
Block a user