Add specs for single-, triple-, and cmd-clicking

This commit is contained in:
Nathan Sobo
2017-03-09 20:41:42 -07:00
committed by Antonio Scandurra
parent 2996500d90
commit 35753c3a8d
3 changed files with 148 additions and 10 deletions

View File

@@ -393,6 +393,11 @@ class TextEditorComponent {
})
}
// This is easier to mock
getPlatform () {
return process.platform
}
queryDecorationsToRender () {
this.decorationsToRender.lineNumbers.clear()
this.decorationsToRender.lines.clear()
@@ -739,14 +744,27 @@ class TextEditorComponent {
const {model} = this.props
const screenPosition = this.screenPositionForMouseEvent(event)
const addOrRemoveSelection = event.metaKey || (event.ctrlKey && this.getPlatform() !== 'darwin')
switch (event.detail) {
case 1:
model.setCursorScreenPosition(screenPosition)
if (addOrRemoveSelection) {
const existingSelection = model.getSelectionAtScreenPosition(screenPosition)
if (existingSelection) {
if (model.hasMultipleCursors()) existingSelection.destroy()
} else {
model.addCursorAtScreenPosition(screenPosition)
}
} else {
model.setCursorScreenPosition(screenPosition)
}
break
case 2:
if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition)
model.getLastSelection().selectWord({autoscroll: false})
break
case 3:
if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition)
model.getLastSelection().selectLine(null, {autoscroll: false})
break
}

View File

@@ -2096,9 +2096,9 @@ class TextEditor extends Model
#
# Returns the first matched {Cursor} or undefined
getCursorAtScreenPosition: (position) ->
for cursor in @cursors
return cursor if cursor.getScreenPosition().isEqual(position)
undefined
if selection = @getSelectionAtScreenPosition(position)
if selection.getHeadScreenPosition().isEqual(position)
selection.cursor
# Essential: Get the position of the most recently added cursor in screen
# coordinates.
@@ -2647,6 +2647,12 @@ class TextEditor extends Model
@createLastSelectionIfNeeded()
_.last(@selections)
getSelectionAtScreenPosition: (position) ->
debugger if global.debug
markers = @selectionsMarkerLayer.findMarkers(containsScreenPosition: position)
if markers.length > 0
@cursorsByMarkerId.get(markers[0].id).selection
# Extended: Get current {Selection}s.
#
# Returns: An {Array} of {Selection}s.