mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
Corretly select word and line w/ mouse with wraps and folds
This commit is contained in:
parent
eaf76798ae
commit
eeae6c4ee2
@ -344,19 +344,55 @@ describe "Editor", ->
|
||||
editor.attachToDom()
|
||||
editor.css(position: 'absolute', top: 10, left: 10)
|
||||
|
||||
describe "when soft-wrap is enabled", ->
|
||||
describe "when soft-wrap and is enabled and code is folded", ->
|
||||
beforeEach ->
|
||||
editor.width(editor.charWidth * 50)
|
||||
editor.setSoftWrap(true)
|
||||
editor.lineFolder.createFold(new Range([3, 3], [3, 7]))
|
||||
|
||||
describe "when it is a single click", ->
|
||||
it "re-positions the cursor from the clicked screen position to the corresponding buffer position", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [4, 7])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY})
|
||||
expect(editor.getCursorBufferPosition()).toEqual(row: 3, column: 58)
|
||||
|
||||
describe "when it is a double click", ->
|
||||
it "selects the word under the cursor", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [4, 3])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
expect(editor.getSelectedText()).toBe "right"
|
||||
|
||||
describe "when it is clicked more then twice (triple, quadruple, etc...)", ->
|
||||
it "selects the line under the cursor", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
# Triple click
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [4, 3])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 3}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
expect(editor.getSelectedText()).toBe " var pivot = items.shift(), current, left = [], right = [];"
|
||||
|
||||
# Quad click
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [8, 3])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 3}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 4}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
|
||||
expect(editor.getSelectedText()).toBe " current < pivot ? left.push(current) : right.push(current);"
|
||||
|
||||
describe "when soft-wrap is disabled", ->
|
||||
describe "when it is a single click", ->
|
||||
it "re-positions the cursor to the clicked row / column", ->
|
||||
@ -371,35 +407,36 @@ describe "Editor", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [0, 8])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
expect(editor.getSelectedText()).toBe "quicksort"
|
||||
|
||||
describe "when it is clicked more then twice (tripple, quadruple, etc...)", ->
|
||||
describe "when it is clicked more then twice (triple, quadruple, etc...)", ->
|
||||
it "selects the line under the cursor", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
# Triple click
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [1, 8])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 3}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
expect(editor.getSelectedText()).toBe " var sort = function(items) {"
|
||||
$(document).trigger 'mouseup'
|
||||
|
||||
# Quad click
|
||||
[pageX, pageY] = window.pixelPositionForPoint(editor, [2, 3])
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 1}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 2}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 3}})
|
||||
$(document).trigger 'mouseup'
|
||||
editor.lines.trigger 'mouseup'
|
||||
editor.lines.trigger mousedownEvent({pageX, pageY, originalEvent: {detail: 4}})
|
||||
editor.lines.trigger 'mouseup'
|
||||
expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;"
|
||||
$(document).trigger 'mouseup'
|
||||
|
||||
describe "selection", ->
|
||||
selection = null
|
||||
|
@ -104,7 +104,7 @@ class Editor extends View
|
||||
else if clickCount == 2
|
||||
@selection.selectWord()
|
||||
else if clickCount >= 3
|
||||
@selection.selectLine(@getCursorRow())
|
||||
@selection.selectLine()
|
||||
|
||||
@selectTextOnMouseMovement()
|
||||
|
||||
@ -169,9 +169,6 @@ class Editor extends View
|
||||
@buffer.on 'change', (e) =>
|
||||
@cursor.bufferChanged(e)
|
||||
|
||||
@lineFolder.on 'fold', (range) =>
|
||||
@setCursorBufferPosition(range.end)
|
||||
|
||||
@lineWrapper.on 'change', (e) =>
|
||||
{ oldRange, newRange } = e
|
||||
screenLines = @linesForScreenRows(newRange.start.row, newRange.end.row)
|
||||
|
@ -108,6 +108,8 @@ class Selection extends View
|
||||
row = @cursor.getRow()
|
||||
column = @cursor.getColumn()
|
||||
|
||||
{ row, column } = @cursor.getBufferPosition()
|
||||
|
||||
line = @editor.buffer.getLine(row)
|
||||
leftSide = line[0...column].split('').reverse().join('') # reverse left side
|
||||
rightSide = line[column..]
|
||||
@ -119,7 +121,7 @@ class Selection extends View
|
||||
range = new Range([row, column + startOffset], [row, column + endOffset])
|
||||
@setBufferRange range
|
||||
|
||||
selectLine: (row) ->
|
||||
selectLine: (row=@cursor.getBufferPosition().row) ->
|
||||
rowLength = @editor.buffer.getLine(row).length
|
||||
@setBufferRange new Range([row, 0], [row, rowLength])
|
||||
|
||||
@ -167,4 +169,6 @@ class Selection extends View
|
||||
atom.native.writeToPasteboard text
|
||||
|
||||
fold: ->
|
||||
@editor.lineFolder.createFold(@getBufferRange())
|
||||
range = @getBufferRange()
|
||||
@editor.lineFolder.createFold(range)
|
||||
@cursor.setBufferPosition(range.end)
|
||||
|
Loading…
Reference in New Issue
Block a user