mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Double clicking selects a word.
This commit is contained in:
@@ -244,22 +244,30 @@ describe "Editor", ->
|
||||
|
||||
expect(editor.getCursorPosition()).toEqual(lastPosition)
|
||||
|
||||
|
||||
describe "when a mousedown event occurs in the editor", ->
|
||||
it "re-positions the cursor to the clicked row / column", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
expect(editor.getCursorPosition()).toEqual(row: 0, column: 0)
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [3, 10])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY})
|
||||
expect(editor.getCursorPosition()).toEqual(row: 3, column: 10)
|
||||
describe "when it is a single click", ->
|
||||
it "re-positions the cursor to the clicked row / column", ->
|
||||
editor.attachToDom()
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
describe "when doubleclick occurs in the editor", ->
|
||||
it "selects the word under the cursor", ->
|
||||
editor.attachToDom()
|
||||
expect(editor.getCursorPosition()).toEqual(row: 0, column: 0)
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [0, 8])
|
||||
editor.lines.trigger mouseupEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
expect(editor.getSelectedText()).toBe "quicksort"
|
||||
expect(editor.getCursorPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [3, 10])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY})
|
||||
expect(editor.getCursorPosition()).toEqual(row: 3, column: 10)
|
||||
|
||||
describe "when it is a double click", ->
|
||||
it "selects the word under the cursor", ->
|
||||
expect(editor.getCursorPosition()).toEqual(row: 0, column: 0)
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [0, 8])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
expect(editor.getSelectedText()).toBe "quicksort"
|
||||
|
||||
describe "selection", ->
|
||||
selection = null
|
||||
@@ -325,6 +333,7 @@ describe "Editor", ->
|
||||
describe "when the mouse is dragged across the text", ->
|
||||
it "creates a selection from the initial click to mouse cursor's location ", ->
|
||||
editor.attachToDom()
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
# start
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [4, 10])
|
||||
|
||||
@@ -33,11 +33,9 @@ window.clickEvent = (properties={}) ->
|
||||
$.Event "click", properties
|
||||
|
||||
window.mousedownEvent = (properties={}) ->
|
||||
properties.originalEvent ?= {detail: 1}
|
||||
$.Event "mousedown", properties
|
||||
|
||||
window.mouseupEvent = (properties={}) ->
|
||||
$.Event "mouseup", properties
|
||||
|
||||
window.mousemoveEvent = (properties={}) ->
|
||||
$.Event "mousemove", properties
|
||||
|
||||
@@ -68,8 +66,6 @@ window.advanceClock = (delta) ->
|
||||
true
|
||||
|
||||
window.pixelPositionForPoint = (editor, point) ->
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
point = Point.fromObject point
|
||||
pageY = editor.offset().top + point.row * editor.lineHeight + 1 # ensure the pixel is inside the char
|
||||
pageX = editor.offset().left + point.column * editor.charWidth + 1 # ensure the pixel is inside the char
|
||||
|
||||
@@ -76,15 +76,14 @@ class Editor extends Template
|
||||
false
|
||||
|
||||
@on 'mousedown', (e) =>
|
||||
@setCursorPosition @pointFromMouseEvent(e)
|
||||
moveHandler = (e) => @selectToPosition(@pointFromMouseEvent(e))
|
||||
@on 'mousemove', moveHandler
|
||||
$(document).one 'mouseup', => @off 'mousemove', moveHandler
|
||||
|
||||
@on 'mouseup', (e) =>
|
||||
clickCount = e.originalEvent.detail
|
||||
if clickCount == 2
|
||||
|
||||
if clickCount == 1
|
||||
@setCursorPosition @pointFromMouseEvent(e)
|
||||
moveHandler = (e) => @selectToPosition(@pointFromMouseEvent(e))
|
||||
@on 'mousemove', moveHandler
|
||||
$(document).one 'mouseup', => @off 'mousemove', moveHandler
|
||||
else if clickCount == 2
|
||||
@selection.selectWord()
|
||||
|
||||
@hiddenInput.on "textInput", (e) =>
|
||||
|
||||
Reference in New Issue
Block a user