mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Allow drag-dropping into plaintext editor (#3902)
* expose field index as data attr on container * allow drag/dropping into fields' plaintext editors
This commit is contained in:
parent
0f9216c127
commit
d9c71a54cf
2 changed files with 20 additions and 6 deletions
|
@ -60,6 +60,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let collapsed = false;
|
export let collapsed = false;
|
||||||
export let flipInputs = false;
|
export let flipInputs = false;
|
||||||
export let dupe = false;
|
export let dupe = false;
|
||||||
|
export let index;
|
||||||
|
|
||||||
const directionStore = writable<"ltr" | "rtl">();
|
const directionStore = writable<"ltr" | "rtl">();
|
||||||
setContext(directionKey, directionStore);
|
setContext(directionKey, directionStore);
|
||||||
|
@ -95,6 +96,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
role="presentation"
|
role="presentation"
|
||||||
|
data-index={index}
|
||||||
>
|
>
|
||||||
<slot name="field-label" />
|
<slot name="field-label" />
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
import { bridgeCommand } from "@tslib/bridgecommand";
|
||||||
import { onMount, tick } from "svelte";
|
import { onMount, tick } from "svelte";
|
||||||
import { get, writable } from "svelte/store";
|
import { get, writable } from "svelte/store";
|
||||||
|
import { nodeIsCommonElement } from "@tslib/dom";
|
||||||
|
|
||||||
import Absolute from "$lib/components/Absolute.svelte";
|
import Absolute from "$lib/components/Absolute.svelte";
|
||||||
import Badge from "$lib/components/Badge.svelte";
|
import Badge from "$lib/components/Badge.svelte";
|
||||||
|
@ -322,15 +323,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
export function focusIfField(x: number, y: number): boolean {
|
export function focusIfField(x: number, y: number): boolean {
|
||||||
const elements = document.elementsFromPoint(x, y);
|
const elements = document.elementsFromPoint(x, y);
|
||||||
const first = elements[0];
|
const first = elements[0].closest(".field-container");
|
||||||
|
|
||||||
if (first.shadowRoot) {
|
if (!first || !nodeIsCommonElement(first)) {
|
||||||
const richTextInput = first.shadowRoot.lastElementChild! as HTMLElement;
|
return false;
|
||||||
richTextInput.focus();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
const index = parseInt(first.dataset?.index ?? "");
|
||||||
|
|
||||||
|
if (Number.isNaN(index) || !fields[index] || fieldsCollapsed[index]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (richTextsHidden[index]) {
|
||||||
|
toggleRichTextInput(index);
|
||||||
|
} else {
|
||||||
|
richTextInputs[index].api.refocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let richTextInputs: RichTextInput[] = [];
|
let richTextInputs: RichTextInput[] = [];
|
||||||
|
@ -668,6 +679,7 @@ the AddCards dialog) should be implemented in the user of this component.
|
||||||
<EditorField
|
<EditorField
|
||||||
{field}
|
{field}
|
||||||
{content}
|
{content}
|
||||||
|
{index}
|
||||||
flipInputs={plainTextDefaults[index]}
|
flipInputs={plainTextDefaults[index]}
|
||||||
api={fields[index]}
|
api={fields[index]}
|
||||||
on:focusin={() => {
|
on:focusin={() => {
|
||||||
|
|
Loading…
Reference in a new issue