Move showDupes()

This commit is contained in:
Abdo 2025-06-02 03:41:58 +03:00
parent 0966cd4552
commit 8391761bc2
3 changed files with 30 additions and 25 deletions

View file

@ -30,7 +30,7 @@ import aqt.operations
import aqt.sound import aqt.sound
from anki._legacy import deprecated from anki._legacy import deprecated
from anki.cards import Card from anki.cards import Card
from anki.collection import Config, SearchNode from anki.collection import Config
from anki.consts import MODEL_CLOZE from anki.consts import MODEL_CLOZE
from anki.hooks import runFilter from anki.hooks import runFilter
from anki.httpclient import HttpClient from anki.httpclient import HttpClient
@ -588,21 +588,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
"}); " "}); "
) )
def showDupes(self) -> None:
assert self.note is not None
aqt.dialogs.open(
"Browser",
self.mw,
search=(
SearchNode(
dupe=SearchNode.Dupe(
notetype_id=self.note_type()["id"],
first_field=self.note.fields[0],
)
),
),
)
def fieldsAreBlank(self, previousNote: Note | None = None) -> bool: def fieldsAreBlank(self, previousNote: Note | None = None) -> bool:
if not self.note: if not self.note:
return True return True
@ -1268,7 +1253,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
attach=Editor.onAddMedia, attach=Editor.onAddMedia,
record=Editor.onRecSound, record=Editor.onRecSound,
more=Editor.onAdvanced, more=Editor.onAdvanced,
dupes=Editor.showDupes,
paste=Editor.onPaste, paste=Editor.onPaste,
cutOrCopy=Editor.onCutOrCopy, cutOrCopy=Editor.onCutOrCopy,
htmlEdit=Editor.onHtmlEdit, htmlEdit=Editor.onHtmlEdit,

View file

@ -3,12 +3,29 @@ 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 lang="ts">
import { searchInBrowser } from "@generated/backend";
import * as tr from "@generated/ftl"; import * as tr from "@generated/ftl";
import { bridgeCommand } from "@tslib/bridgecommand"; import type { Note } from "@generated/anki/notes_pb";
export let note: Note | null = null;
function showDupes() {
if (note) {
searchInBrowser({
filter: {
case: "dupe",
value: {
notetypeId: note.notetypeId,
firstField: note.fields[0],
},
},
});
}
}
</script> </script>
<span class="duplicate-link-container"> <span class="duplicate-link-container">
<a class="duplicate-link" href="/#" on:click={() => bridgeCommand("dupes")}> <a class="duplicate-link" href="/#" on:click={showDupes}>
{tr.editingShowDuplicates()} {tr.editingShowDuplicates()}
</a> </a>
</span> </span>

View file

@ -585,7 +585,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}); });
} }
async function loadNote(nid: bigint, notetypeId: bigint, focusTo: number, originalNoteId: bigint | null) { async function loadNote(
nid: bigint,
notetypeId: bigint,
focusTo: number,
originalNoteId: bigint | null,
) {
const notetype = await getNotetype({ const notetype = await getNotetype({
ntid: notetypeId, ntid: notetypeId,
}); });
@ -647,10 +652,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
if (mode === "add") { if (mode === "add") {
setSticky(notetype.fields.map((field) => field.config?.sticky ?? false)); setSticky(notetype.fields.map((field) => field.config?.sticky ?? false));
} }
if(isImageOcclusion) { if (isImageOcclusion) {
const imageField = note!.fields[ioFields.image]; const imageField = note!.fields[ioFields.image];
// TODO: last_io_image_path // TODO: last_io_image_path
if(mode !== "add") { if (mode !== "add") {
setupMaskEditor({ setupMaskEditor({
html: imageField, html: imageField,
mode: { mode: {
@ -658,8 +663,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
noteId: nid, noteId: nid,
}, },
}); });
} } else if (originalNoteId) {
else if(originalNoteId) {
setupMaskEditor({ setupMaskEditor({
html: imageField, html: imageField,
mode: { mode: {
@ -863,7 +867,7 @@ components and functionality for general note editing.
</svelte:fragment> </svelte:fragment>
<FieldState> <FieldState>
{#if cols[index] === "dupe"} {#if cols[index] === "dupe"}
<DuplicateLink /> <DuplicateLink {note} />
{/if} {/if}
{#if mode === "add"} {#if mode === "add"}
<StickyBadge <StickyBadge