mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
When shift-clicking, select to the clicked position
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
React = require 'react'
|
||||
{extend} = require 'underscore-plus'
|
||||
EditorComponent = require '../src/editor-component'
|
||||
|
||||
describe "EditorComponent", ->
|
||||
@@ -163,6 +164,23 @@ describe "EditorComponent", ->
|
||||
expect(region3Rect.width).toBe 10 * charWidth
|
||||
|
||||
describe "mouse interactions", ->
|
||||
describe "when a non-folded line is single-clicked", ->
|
||||
describe "when no modifier keys are held down", ->
|
||||
it "moves the cursor to the nearest row and column", ->
|
||||
node.style.height = 4.5 * lineHeightInPixels + 'px'
|
||||
component.updateAllDimensions()
|
||||
editor.setScrollTop(3.5 * lineHeightInPixels)
|
||||
|
||||
component.onMouseDown(clientCoordinatesForScreenPosition([4, 8]))
|
||||
expect(editor.getCursorScreenPosition()).toEqual [4, 8]
|
||||
|
||||
describe "when the shift key is held down", ->
|
||||
it "selects to the nearest row and column", ->
|
||||
editor.setCursorScreenPosition([3, 4])
|
||||
event = extend(clientCoordinatesForScreenPosition([5, 6]), shiftKey: true)
|
||||
component.onMouseDown(event)
|
||||
expect(editor.getSelectedScreenRange()).toEqual [[3, 4], [5, 6]]
|
||||
|
||||
clientCoordinatesForScreenPosition = (screenPosition) ->
|
||||
positionOffset = editor.pixelPositionForScreenPosition(screenPosition)
|
||||
editorClientRect = node.getBoundingClientRect()
|
||||
@@ -170,14 +188,6 @@ describe "EditorComponent", ->
|
||||
clientY = editorClientRect.top + positionOffset.top - editor.getScrollTop()
|
||||
{clientX, clientY}
|
||||
|
||||
describe "when a non-folded line is single-clicked", ->
|
||||
it "moves the cursor to the nearest row and column", ->
|
||||
node.style.height = 4.5 * lineHeightInPixels + 'px'
|
||||
component.updateAllDimensions()
|
||||
editor.setScrollTop(3.5 * lineHeightInPixels)
|
||||
component.onMouseDown(clientCoordinatesForScreenPosition([4, 8]))
|
||||
expect(editor.getCursorScreenPosition()).toEqual [4, 8]
|
||||
|
||||
it "transfers focus to the hidden input", ->
|
||||
expect(document.activeElement).toBe document.body
|
||||
node.focus()
|
||||
|
||||
@@ -269,14 +269,18 @@ EditorCompont = React.createClass
|
||||
|
||||
onMouseDown: (event) ->
|
||||
{editor} = @props
|
||||
{clientX, clientY} = event
|
||||
{clientX, clientY, shiftKey} = event
|
||||
editorClientRect = @refs.scrollView.getDOMNode().getBoundingClientRect()
|
||||
|
||||
pixelPosition =
|
||||
top: clientY - editorClientRect.top + editor.getScrollTop()
|
||||
left: clientX - editorClientRect.left
|
||||
screenPosition = editor.screenPositionForPixelPosition(pixelPosition)
|
||||
editor.setCursorScreenPosition(screenPosition)
|
||||
|
||||
if shiftKey
|
||||
editor.selectToScreenPosition(screenPosition)
|
||||
else
|
||||
editor.setCursorScreenPosition(screenPosition)
|
||||
|
||||
clearVisibleRowOverrides: ->
|
||||
@visibleRowOverrides = null
|
||||
|
||||
Reference in New Issue
Block a user