Disallow draggin of mathjax + only ever have one handle active

This commit is contained in:
Henrik Giesel 2021-08-07 04:04:42 +02:00
parent 9ef4bb15c6
commit 7ba85a2fbe
3 changed files with 16 additions and 7 deletions

View file

@ -12,7 +12,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: encoded = encodeURIComponent(converted); $: encoded = encodeURIComponent(converted);
</script> </script>
<img src="data:image/svg+xml,{encoded}" class:block alt="Mathjax" data-anki="mathjax" /> <img
src="data:image/svg+xml,{encoded}"
class:block
alt="Mathjax"
data-anki="mathjax"
on:dragstart|preventDefault
/>
<style lang="scss"> <style lang="scss">
img { img {

View file

@ -130,7 +130,6 @@ export const Mathjax: DecoratedElementConstructor = class Mathjax
connectedCallback(): void { connectedCallback(): void {
this.decorate(); this.decorate();
// TODO text is assigned white-space: normal
this.disconnect = moveNodesInsertedOutside(this, this.children[0]); this.disconnect = moveNodesInsertedOutside(this, this.children[0]);
} }

View file

@ -222,8 +222,8 @@ export class EditingArea extends HTMLDivElement {
this.activeInput.onPaste(event); this.activeInput.onPaste(event);
} }
resetHandles(): void { resetHandles(): Promise<void> {
this.imageHandle.then((imageHandle) => const promise = this.imageHandle.then((imageHandle) =>
(imageHandle as any).$set({ (imageHandle as any).$set({
activeImage: null, activeImage: null,
}) })
@ -232,12 +232,16 @@ export class EditingArea extends HTMLDivElement {
(this.mathjaxHandle as any).$set({ (this.mathjaxHandle as any).$set({
activeImage: null, activeImage: null,
}); });
return promise;
} }
showHandles(event: MouseEvent): void { async showHandles(event: MouseEvent): Promise<void> {
if (event.target instanceof HTMLImageElement) { if (event.target instanceof HTMLImageElement) {
await this.resetHandles();
if (!event.target.dataset.anki) { if (!event.target.dataset.anki) {
this.imageHandle.then((imageHandle) => await this.imageHandle.then((imageHandle) =>
(imageHandle as any).$set({ (imageHandle as any).$set({
activeImage: event.target, activeImage: event.target,
isRtl: this.isRightToLeft(), isRtl: this.isRightToLeft(),
@ -250,7 +254,7 @@ export class EditingArea extends HTMLDivElement {
}); });
} }
} else { } else {
this.resetHandles(); await this.resetHandles();
} }
} }