mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 14:17:13 -05:00
Remove mediaPromise
This commit is contained in:
parent
cf099ea508
commit
f4293c1f9e
1 changed files with 2 additions and 27 deletions
|
|
@ -4,8 +4,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "@generated/ftl";
|
import * as tr from "@generated/ftl";
|
||||||
import { promiseWithResolver } from "@tslib/promise";
|
|
||||||
import { registerPackage } from "@tslib/runtime-require";
|
|
||||||
import { getPlatformString } from "@tslib/shortcuts";
|
import { getPlatformString } from "@tslib/shortcuts";
|
||||||
|
|
||||||
import ButtonGroup from "$lib/components/ButtonGroup.svelte";
|
import ButtonGroup from "$lib/components/ButtonGroup.svelte";
|
||||||
|
|
@ -22,7 +20,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import { context } from "../NoteEditor.svelte";
|
import { context } from "../NoteEditor.svelte";
|
||||||
import { setFormat } from "../old-editor-adapter";
|
import { setFormat } from "../old-editor-adapter";
|
||||||
import type { RichTextInputAPI } from "../rich-text-input";
|
|
||||||
import { editingInputIsRichText } from "../rich-text-input";
|
import { editingInputIsRichText } from "../rich-text-input";
|
||||||
import LatexButton from "./LatexButton.svelte";
|
import LatexButton from "./LatexButton.svelte";
|
||||||
import { filenameToLink, openFilePickerForMedia } from "../rich-text-input/data-transfer";
|
import { filenameToLink, openFilePickerForMedia } from "../rich-text-input/data-transfer";
|
||||||
|
|
@ -32,35 +29,19 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
const attachmentCombination = "F3";
|
const attachmentCombination = "F3";
|
||||||
|
|
||||||
let mediaPromise: Promise<string>;
|
async function attachPath(path: string) {
|
||||||
let resolve: (media: string) => void;
|
|
||||||
|
|
||||||
function resolveMedia(media: string): void {
|
|
||||||
resolve?.(media);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function attachPath(path: string): Promise<void> {
|
|
||||||
const filename = (await addMediaFromPath({ path })).val;
|
const filename = (await addMediaFromPath({ path })).val;
|
||||||
resolveMedia(filenameToLink(filename));
|
setFormat("inserthtml", filenameToLink(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function attachMediaOnFocus(): Promise<void> {
|
async function attachMediaOnFocus(): Promise<void> {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[mediaPromise, resolve] = promiseWithResolver<string>();
|
|
||||||
($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
|
|
||||||
async () => setFormat("inserthtml", await mediaPromise),
|
|
||||||
{ once: true },
|
|
||||||
);
|
|
||||||
const path = await openFilePickerForMedia();
|
const path = await openFilePickerForMedia();
|
||||||
await attachPath(path);
|
await attachPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerPackage("anki/TemplateButtons", {
|
|
||||||
resolveMedia,
|
|
||||||
});
|
|
||||||
|
|
||||||
const recordCombination = "F5";
|
const recordCombination = "F5";
|
||||||
|
|
||||||
|
|
@ -68,12 +49,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[mediaPromise, resolve] = promiseWithResolver<string>();
|
|
||||||
($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
|
|
||||||
async () => setFormat("inserthtml", await mediaPromise),
|
|
||||||
{ once: true },
|
|
||||||
);
|
|
||||||
const path = (await recordAudio({})).val;
|
const path = (await recordAudio({})).val;
|
||||||
await attachPath(path);
|
await attachPath(path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue