Merge pull request #15299 from atom/as-do-nothing-when-clicking-on-block-decorations

Ignore clicks on block decorations
This commit is contained in:
Nathan Sobo
2017-08-14 08:59:27 -06:00
committed by GitHub
2 changed files with 45 additions and 0 deletions

View File

@@ -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')

View File

@@ -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.