mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Set cursor position on single click
This commit is contained in:
parent
88f3a5b468
commit
fab5a93254
@ -592,6 +592,58 @@ describe('TextEditorComponent', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('mouse input', () => {
|
||||
it('positions the cursor on single click', async () => {
|
||||
const {component, element, editor} = buildComponent()
|
||||
const {lineHeight, baseCharacterWidth} = component.measurements
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: clientLeftForCharacter(component, 0, editor.lineLengthForScreenRow(0)) + 1,
|
||||
clientY: clientTopForLine(component, 0) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, editor.lineLengthForScreenRow(0)])
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: (clientLeftForCharacter(component, 3, 0) + clientLeftForCharacter(component, 3, 1)) / 2,
|
||||
clientY: clientTopForLine(component, 1) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1, 0])
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: (clientLeftForCharacter(component, 3, 14) + clientLeftForCharacter(component, 3, 15)) / 2,
|
||||
clientY: clientTopForLine(component, 3) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([3, 14])
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: (clientLeftForCharacter(component, 3, 14) + clientLeftForCharacter(component, 3, 15)) / 2 + 1,
|
||||
clientY: clientTopForLine(component, 3) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([3, 15])
|
||||
|
||||
editor.getBuffer().setTextInRange([[3, 14], [3, 15]], '🐣')
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: (clientLeftForCharacter(component, 3, 14) + clientLeftForCharacter(component, 3, 16)) / 2,
|
||||
clientY: clientTopForLine(component, 3) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([3, 14])
|
||||
|
||||
component.didMouseDownOnLines({
|
||||
detail: 1,
|
||||
clientX: (clientLeftForCharacter(component, 3, 14) + clientLeftForCharacter(component, 3, 16)) / 2 + 1,
|
||||
clientY: clientTopForLine(component, 3) + lineHeight / 2
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([3, 16])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function buildComponent (params = {}) {
|
||||
|
@ -736,7 +736,11 @@ class TextEditorComponent {
|
||||
}
|
||||
|
||||
didMouseDownOnLines (event) {
|
||||
console.log(this.screenPositionForMouseEvent(event))
|
||||
const screenPosition = this.screenPositionForMouseEvent(event)
|
||||
|
||||
if (event.detail === 1) {
|
||||
this.props.model.setCursorScreenPosition(screenPosition)
|
||||
}
|
||||
}
|
||||
|
||||
screenPositionForMouseEvent ({clientX, clientY}) {
|
||||
|
Loading…
Reference in New Issue
Block a user