mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Ignore clicks on block decorations
Previously, clicking on a block decoration to interact with it would cause the editor to scroll to the line next to it. This is inconvenient, especially if the decoration was designed to be interactive and contained buttons or links. If the decoration was close to the bottom of the screen, clicking on a button inside of it would make the editor scroll down and abort the click. This behavior regressed during the editor rendering layer rewrite and with this commit we are restoring the original behavior by simply ignoring clicks that land 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')
|
||||
|
||||
Reference in New Issue
Block a user