mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-27 00:36:44 +03:00
Improved SquireUI handling of pathChange and bugfix bold match
This commit is contained in:
parent
48acb9ca38
commit
12b6ed3dbb
2 changed files with 24 additions and 30 deletions
19
dev/External/SquireUI.js
vendored
19
dev/External/SquireUI.js
vendored
|
|
@ -155,7 +155,7 @@ class SquireUI
|
|||
html: 'B',
|
||||
cmd: () => this.doAction('bold'),
|
||||
key: 'B',
|
||||
matches: 'B,STRONT'
|
||||
matches: 'B,STRONG'
|
||||
},
|
||||
italic: {
|
||||
html: 'I',
|
||||
|
|
@ -477,15 +477,22 @@ class SquireUI
|
|||
|
||||
// -----
|
||||
|
||||
squire.addEventListener('pathChange', e => {
|
||||
squire.addEventListener('pathChange', () => {
|
||||
|
||||
const squireRoot = squire.getRoot();
|
||||
let elm = e.detail.element;
|
||||
|
||||
let range = squire.getSelection(),
|
||||
collapsed = range.collapsed,
|
||||
elm = collapsed ? range.endContainer : range?.commonAncestorContainer;
|
||||
if (elm && !(elm instanceof Element)) {
|
||||
elm = elm.parentElement;
|
||||
}
|
||||
forEachObjectValue(actions, entries => {
|
||||
forEachObjectValue(entries, cfg => {
|
||||
// cfg.matches && cfg.input.classList.toggle('active', elm && elm.matches(cfg.matches));
|
||||
cfg.matches && cfg.input.classList.toggle('active', elm && elm.closestWithin(cfg.matches, squireRoot));
|
||||
// Check if selection has a matching parent or contains a matching element
|
||||
cfg.matches && cfg.input.classList.toggle('active', !!(elm && (
|
||||
(!collapsed && [...elm.querySelectorAll(cfg.matches)].some(node => range.intersectsNode(node)))
|
||||
|| elm.closestWithin(cfg.matches, squireRoot)
|
||||
)));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue