ezqms-748: hide left menu by default, ensure placement, improve show/hide logic (#5429)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-04-23 14:20:01 +04:00 committed by GitHub
parent 7563aaa862
commit 703960d4ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -590,6 +590,7 @@
flex-grow: 1;
display: flex;
flex-direction: column;
position: relative;
}
.text-editor-toolbar {

View File

@ -73,6 +73,7 @@ function LeftMenu (options: LeftMenuOptions): Plugin {
leftMenuElement = document.createElement('div')
leftMenuElement.classList.add(options.className) // Style externally with CSS
leftMenuElement.style.position = 'absolute'
hideLeftMenu()
const svgNs = 'http://www.w3.org/2000/svg'
const icon = document.createElementNS(svgNs, 'svg')
@ -132,7 +133,7 @@ function LeftMenu (options: LeftMenuOptions): Plugin {
y: event.clientY
})
if (!(node instanceof HTMLElement)) {
if (!(node instanceof HTMLElement) || node.nodeName === 'HR') {
hideLeftMenu()
return
}
@ -174,6 +175,26 @@ function LeftMenu (options: LeftMenuOptions): Plugin {
},
mousewheel: () => {
hideLeftMenu()
},
mouseleave: (view, event) => {
if (!view.editable) {
return
}
const node = nodeDOMAtCoords({
x: event.clientX + offsetX,
y: event.clientY
})
if (!(node instanceof HTMLElement) || node.nodeName === 'HR') {
hideLeftMenu()
return
}
const parent = node?.parentElement
if (!(parent instanceof HTMLElement)) {
hideLeftMenu()
}
}
}
}