mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Text is selected when mouse is moved after double click
This commit is contained in:
@@ -385,6 +385,37 @@ describe "Editor", ->
|
||||
expect(range.end).toEqual({row: 5, column: 27})
|
||||
expect(editor.getCursorPosition()).toEqual(row: 5, column: 27)
|
||||
|
||||
fit "creates a selection from the initial double click to mouse cursor's location ", ->
|
||||
editor.attachToDom()
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
# double click
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [4, 10])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
|
||||
# moving changes selection
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [5, 27])
|
||||
editor.lines.trigger mousemoveEvent({pageX, pageY})
|
||||
|
||||
range = editor.selection.getRange()
|
||||
expect(range.start).toEqual({row: 4, column: 10})
|
||||
expect(range.end).toEqual({row: 5, column: 27})
|
||||
expect(editor.getCursorPosition()).toEqual(row: 5, column: 27)
|
||||
|
||||
# mouse up may occur outside of editor, but still need to halt selection
|
||||
$(document).trigger 'mouseup'
|
||||
|
||||
# moving after mouse up should not change selection
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [8, 8])
|
||||
editor.lines.trigger mousemoveEvent({pageX, pageY})
|
||||
|
||||
range = editor.selection.getRange()
|
||||
expect(range.start).toEqual({row: 4, column: 10})
|
||||
expect(range.end).toEqual({row: 5, column: 27})
|
||||
expect(editor.getCursorPosition()).toEqual(row: 5, column: 27)
|
||||
|
||||
describe "buffer manipulation", ->
|
||||
describe "when text input events are triggered on the hidden input element", ->
|
||||
describe "when there is no selection", ->
|
||||
|
||||
@@ -83,11 +83,10 @@ class Editor extends Template
|
||||
|
||||
if clickCount == 1
|
||||
@setCursorPosition @pointFromMouseEvent(e)
|
||||
moveHandler = (e) => @selectToPosition(@pointFromMouseEvent(e))
|
||||
@on 'mousemove', moveHandler
|
||||
$(document).one 'mouseup', => @off 'mousemove', moveHandler
|
||||
@selectTextOnMouseMovement()
|
||||
else if clickCount == 2
|
||||
@selection.selectWord()
|
||||
@selectTextOnMouseMovement()
|
||||
|
||||
@hiddenInput.on "textInput", (e) =>
|
||||
@insertText(e.originalEvent.data)
|
||||
@@ -100,6 +99,12 @@ class Editor extends Template
|
||||
@hiddenInput.width(@charWidth)
|
||||
@focus()
|
||||
|
||||
selectTextOnMouseMovement: ->
|
||||
moveHandler = (e) => @selectToPosition(@pointFromMouseEvent(e))
|
||||
@on 'mousemove', moveHandler
|
||||
$(document).one 'mouseup', => @off 'mousemove', moveHandler
|
||||
|
||||
|
||||
buildLineElement: (row) ->
|
||||
tokens = @highlighter.tokensForRow(row)
|
||||
$$.pre class: 'line', ->
|
||||
|
||||
Reference in New Issue
Block a user