Fix current tag text not committed when changing note via shortcut key (#2441)

This commit is contained in:
Hikaru Y 2023-03-16 15:48:29 +09:00 committed by GitHub
parent 5774e5d4af
commit 146bed12d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -48,6 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Absolute from "../components/Absolute.svelte"; import Absolute from "../components/Absolute.svelte";
import Badge from "../components/Badge.svelte"; import Badge from "../components/Badge.svelte";
import { TagEditor } from "../tag-editor"; import { TagEditor } from "../tag-editor";
import { commitTagEdits } from "../tag-editor/TagInput.svelte";
import { ChangeTimer } from "./change-timer"; import { ChangeTimer } from "./change-timer";
import { clearableArray } from "./destroyable"; import { clearableArray } from "./destroyable";
import DuplicateLink from "./DuplicateLink.svelte"; import DuplicateLink from "./DuplicateLink.svelte";
@ -280,11 +281,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
); );
} }
export function saveFieldNow(): void { function saveFieldNow(): void {
/* this will always be a key save */ /* this will always be a key save */
fieldSave.fireImmediately(); fieldSave.fireImmediately();
} }
function saveNow(): void {
commitTagEdits();
saveFieldNow();
}
export function saveOnPageHide() { export function saveOnPageHide() {
if (document.visibilityState === "hidden") { if (document.visibilityState === "hidden") {
// will fire on session close and minimize // will fire on session close and minimize
@ -352,7 +358,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
setTagsCollapsed, setTagsCollapsed,
setBackgrounds, setBackgrounds,
setClozeHint, setClozeHint,
saveNow: saveFieldNow, saveNow,
focusIfField, focusIfField,
getNoteId, getNoteId,
setNoteId, setNoteId,

View File

@ -2,12 +2,21 @@
Copyright: Ankitects Pty Ltd and contributors Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script context="module" lang="ts">
import { createEventDispatcher, getContext, onMount, tick } from "svelte"; let current: HTMLInputElement | null = null;
export function commitTagEdits(): void {
current?.blur();
}
</script>
<script lang="ts">
import { tagActionsShortcutsKey } from "@tslib/context-keys"; import { tagActionsShortcutsKey } from "@tslib/context-keys";
import { isArrowLeft, isArrowRight } from "@tslib/keys"; import { isArrowLeft, isArrowRight } from "@tslib/keys";
import { registerShortcut } from "@tslib/shortcuts"; import { registerShortcut } from "@tslib/shortcuts";
import { createEventDispatcher, getContext, onMount, tick } from "svelte";
import type { ActionReturn } from "svelte/action";
import { import {
delimChar, delimChar,
normalizeTagname, normalizeTagname,
@ -242,6 +251,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
registerShortcut(onSelectAll, selectAllShortcut, { target: input }); registerShortcut(onSelectAll, selectAllShortcut, { target: input });
input.focus(); input.focus();
}); });
function updateCurrent(input: HTMLInputElement): ActionReturn {
current = input;
return {
destroy(): void {
if (current === input) {
current = null;
}
},
};
}
</script> </script>
<input <input
@ -261,6 +281,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:input={() => dispatch("taginput")} on:input={() => dispatch("taginput")}
on:copy|preventDefault={onCopy} on:copy|preventDefault={onCopy}
on:paste|preventDefault={onPaste} on:paste|preventDefault={onPaste}
use:updateCurrent
/> />
<style lang="scss"> <style lang="scss">