When shift-clicking, select to the clicked position

This commit is contained in:
Nathan Sobo
2014-04-06 13:56:38 -06:00
parent 3a433f734c
commit 7738e74df0
2 changed files with 24 additions and 10 deletions

View File

@@ -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()

View File

@@ -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