mirror of
https://github.com/atom/atom.git
synced 2026-02-10 14:45:11 -05:00
Add specs for single-, triple-, and cmd-clicking
This commit is contained in:
committed by
Antonio Scandurra
parent
2996500d90
commit
35753c3a8d
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user