mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Using dropdownApi is much less faulty than using dropdownObject
- Update MathjaxSelection and Dropdown more reliably
This commit is contained in:
parent
c227c7dc39
commit
7c6f6533c1
1 changed files with 18 additions and 19 deletions
|
@ -29,28 +29,32 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
resizeObserver.observe(container);
|
resizeObserver.observe(container);
|
||||||
|
|
||||||
let updateSelection: () => void;
|
let updateSelection: () => void;
|
||||||
|
let dropdownApi: any;
|
||||||
let title: string;
|
let title: string;
|
||||||
|
|
||||||
function getComponent(image: HTMLImageElement): HTMLElement {
|
function getComponent(image: HTMLImageElement): HTMLElement {
|
||||||
return image.closest("anki-mathjax")! as HTMLElement;
|
return image.closest("anki-mathjax")! as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUpdate(event: CustomEvent) {
|
function scheduleDropdownUpdate() {
|
||||||
|
setTimeout(async () => {
|
||||||
|
await tick();
|
||||||
|
dropdownApi.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onEditorUpdate(event: CustomEvent) {
|
||||||
getComponent(activeImage!).dataset.mathjax = event.detail.mathjax;
|
getComponent(activeImage!).dataset.mathjax = event.detail.mathjax;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updateSelection();
|
updateSelection();
|
||||||
title = activeImage!.title;
|
title = activeImage!.title;
|
||||||
|
scheduleDropdownUpdate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WithDropdown
|
<WithDropdown drop="down" autoOpen={true} autoClose={false} let:createDropdown>
|
||||||
placement="bottom"
|
|
||||||
autoOpen={true}
|
|
||||||
autoClose={false}
|
|
||||||
let:createDropdown
|
|
||||||
let:dropdownObject
|
|
||||||
>
|
|
||||||
{#if activeImage}
|
{#if activeImage}
|
||||||
<HandleSelection
|
<HandleSelection
|
||||||
image={activeImage}
|
image={activeImage}
|
||||||
|
@ -58,7 +62,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
offsetX={2}
|
offsetX={2}
|
||||||
offsetY={2}
|
offsetY={2}
|
||||||
bind:updateSelection
|
bind:updateSelection
|
||||||
on:mount={(event) => createDropdown(event.detail.selection)}
|
on:mount={(event) => (dropdownApi = createDropdown(event.detail.selection))}
|
||||||
>
|
>
|
||||||
<HandleBackground {title} />
|
<HandleBackground {title} />
|
||||||
|
|
||||||
|
@ -68,10 +72,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<MathjaxHandleEditor
|
<MathjaxHandleEditor
|
||||||
initialValue={getComponent(activeImage).dataset.mathjax ?? ""}
|
initialValue={getComponent(activeImage).dataset.mathjax ?? ""}
|
||||||
on:update={(event) => {
|
on:update={onEditorUpdate}
|
||||||
onUpdate(event);
|
|
||||||
setTimeout(dropdownObject.update);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<div class="margin-x">
|
<div class="margin-x">
|
||||||
<ButtonToolbar>
|
<ButtonToolbar>
|
||||||
|
@ -79,17 +80,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<MathjaxHandleInlineBlock
|
<MathjaxHandleInlineBlock
|
||||||
{activeImage}
|
{activeImage}
|
||||||
{isRtl}
|
{isRtl}
|
||||||
on:click={async () => {
|
on:click={() => {
|
||||||
await tick();
|
|
||||||
updateSelection();
|
updateSelection();
|
||||||
dropdownObject.update();
|
scheduleDropdownUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Item>
|
</Item>
|
||||||
</ButtonToolbar>
|
</ButtonToolbar>
|
||||||
<div />
|
</div>
|
||||||
</div></DropdownMenu
|
</DropdownMenu>
|
||||||
>
|
|
||||||
{/if}
|
{/if}
|
||||||
</WithDropdown>
|
</WithDropdown>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue