mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #15299 from atom/as-do-nothing-when-clicking-on-block-decorations
Ignore clicks on block decorations
This commit is contained in:
@@ -2153,6 +2153,39 @@ describe('TextEditorComponent', () => {
|
||||
expect(component.refs.blockDecorationMeasurementArea.offsetWidth).toBe(component.getScrollWidth())
|
||||
})
|
||||
|
||||
it('does not change the cursor position when clicking on a block decoration', async () => {
|
||||
const {editor, component} = buildComponent()
|
||||
|
||||
const decorationElement = document.createElement('div')
|
||||
decorationElement.textContent = 'Parent'
|
||||
const childElement = document.createElement('div')
|
||||
childElement.textContent = 'Child'
|
||||
decorationElement.appendChild(childElement)
|
||||
const marker = editor.markScreenPosition([4, 0])
|
||||
editor.decorateMarker(marker, {type: 'block', item: decorationElement})
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
const decorationElementClientRect = decorationElement.getBoundingClientRect()
|
||||
component.didMouseDownOnContent({
|
||||
target: decorationElement,
|
||||
detail: 1,
|
||||
button: 0,
|
||||
clientX: decorationElementClientRect.left,
|
||||
clientY: decorationElementClientRect.top
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, 0])
|
||||
|
||||
const childElementClientRect = childElement.getBoundingClientRect()
|
||||
component.didMouseDownOnContent({
|
||||
target: childElement,
|
||||
detail: 1,
|
||||
button: 0,
|
||||
clientX: childElementClientRect.left,
|
||||
clientY: childElementClientRect.top
|
||||
})
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, 0])
|
||||
})
|
||||
|
||||
function createBlockDecorationAtScreenRow(editor, screenRow, {height, margin, position}) {
|
||||
const marker = editor.markScreenPosition([screenRow, 0], {invalidate: 'never'})
|
||||
const item = document.createElement('div')
|
||||
|
||||
@@ -1689,6 +1689,18 @@ class TextEditorComponent {
|
||||
const {target, button, detail, ctrlKey, shiftKey, metaKey} = event
|
||||
const platform = this.getPlatform()
|
||||
|
||||
// Ignore clicks on block decorations.
|
||||
if (target) {
|
||||
let element = target
|
||||
while (element && element !== this.element) {
|
||||
if (this.blockDecorationsByElement.has(element)) {
|
||||
return
|
||||
}
|
||||
|
||||
element = element.parentElement
|
||||
}
|
||||
}
|
||||
|
||||
// On Linux, position the cursor on middle mouse button click. A
|
||||
// textInput event with the contents of the selection clipboard will be
|
||||
// dispatched by the browser automatically on mouseup.
|
||||
|
||||
Reference in New Issue
Block a user