Fix lint errors

This commit is contained in:
Abdo 2025-06-02 06:14:15 +03:00
parent 05360e2d19
commit 07d3b6d2b5
6 changed files with 28 additions and 21 deletions

View file

@ -387,19 +387,23 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
if type == "blur": if type == "blur":
self.currentField = None self.currentField = None
# run any filters # run any filters
if gui_hooks.editor_did_unfocus_field(False, self.note, ord): if self.note and gui_hooks.editor_did_unfocus_field(
False, self.note, ord
):
# something updated the note; update it after a subsequent focus # something updated the note; update it after a subsequent focus
# event has had time to fire # event has had time to fire
self.mw.progress.timer( self.mw.progress.timer(
100, self.loadNoteKeepingFocus, False, parent=self.widget 100, self.loadNoteKeepingFocus, False, parent=self.widget
) )
else: else:
if self.note:
gui_hooks.editor_did_fire_typing_timer(self.note) gui_hooks.editor_did_fire_typing_timer(self.note)
# focused into field? # focused into field?
elif cmd.startswith("focus"): elif cmd.startswith("focus"):
(type, num) = cmd.split(":", 1) (type, num) = cmd.split(":", 1)
self.last_field_index = self.currentField = int(num) self.last_field_index = self.currentField = int(num)
if self.note:
gui_hooks.editor_did_focus_field(self.note, self.currentField) gui_hooks.editor_did_focus_field(self.note, self.currentField)
elif cmd.startswith("toggleStickyAll"): elif cmd.startswith("toggleStickyAll"):
@ -436,6 +440,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
return new_state return new_state
elif cmd.startswith("saveTags"): elif cmd.startswith("saveTags"):
if self.note:
gui_hooks.editor_did_update_tags(self.note) gui_hooks.editor_did_update_tags(self.note)
elif cmd.startswith("editorState"): elif cmd.startswith("editorState"):
@ -516,6 +521,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
assert self.mw.pm.profile is not None assert self.mw.pm.profile is not None
js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(self.orig_note_id)});" js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(self.orig_note_id)});"
if self.note:
js = gui_hooks.editor_will_load_note(js, self.note, self) js = gui_hooks.editor_will_load_note(js, self.note, self)
self.web.evalWithCallback( self.web.evalWithCallback(
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
@ -523,6 +529,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
@deprecated(replaced_by=load_note) @deprecated(replaced_by=load_note)
def loadNote(self, focusTo: int | None = None) -> None: def loadNote(self, focusTo: int | None = None) -> None:
assert self.note is not None
self.load_note(self.note.mid, focus_to=focusTo) self.load_note(self.note.mid, focus_to=focusTo)
def call_after_note_saved( def call_after_note_saved(

View file

@ -393,7 +393,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
async function addCurrentNoteInner(deckId: bigint) { async function addCurrentNoteInner(deckId: bigint) {
if(!await noteCanBeAdded()) { if (!(await noteCanBeAdded())) {
return; return;
} }
await addNote({ await addNote({
@ -679,7 +679,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} else { } else {
setNote( setNote(
await getNote({ await getNote({
nid!, nid: nid!,
}), }),
); );
} }

View file

@ -15,9 +15,9 @@ async function save(): Promise<void> {
export const load = (async ({ params }) => { export const load = (async ({ params }) => {
let mode: IOMode; let mode: IOMode;
if (/^\d+/.test(params.imagePathOrNoteId)) { if (/^\d+/.test(params.imagePathOrNoteId)) {
mode = { kind: "edit", noteId: Number(params.imagePathOrNoteId) }; mode = { kind: "edit", noteId: BigInt(params.imagePathOrNoteId) };
} else { } else {
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 }; mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0n };
} }
// for adding note from mobile devices // for adding note from mobile devices

View file

@ -31,7 +31,7 @@ export const addOrUpdateNote = async function(
if (mode.kind == "edit") { if (mode.kind == "edit") {
const result = await updateImageOcclusionNote({ const result = await updateImageOcclusionNote({
noteId: BigInt(mode.noteId), noteId: mode.noteId,
occlusions: occlusionCloze, occlusions: occlusionCloze,
header, header,
backExtra, backExtra,
@ -53,7 +53,7 @@ export const addOrUpdateNote = async function(
}; };
// show toast message // show toast message
const showResult = (noteId: number | null, result: OpChanges, count: number) => { const showResult = (noteId: bigint | null, result: OpChanges, count: number) => {
const props = $state({ const props = $state({
message: "", message: "",
type: "error" as "error" | "success", type: "error" as "error" | "success",

View file

@ -50,10 +50,10 @@ export async function setupImageOcclusion(mode: IOMode, target = document.body):
if (window.location.hash.startsWith("#test-")) { if (window.location.hash.startsWith("#test-")) {
const imagePath = window.location.hash.replace("#test-", ""); const imagePath = window.location.hash.replace("#test-", "");
setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0 }); setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0n });
} }
if (window.location.hash.startsWith("#testforedit-")) { if (window.location.hash.startsWith("#testforedit-")) {
const noteId = parseInt(window.location.hash.replace("#testforedit-", "")); const noteId = BigInt(window.location.hash.replace("#testforedit-", ""));
setupImageOcclusion({ kind: "edit", noteId }); setupImageOcclusion({ kind: "edit", noteId });
} }

View file

@ -44,7 +44,7 @@ export const setupMaskEditor = async (
}; };
export const setupMaskEditorForEdit = async ( export const setupMaskEditorForEdit = async (
noteId: number, noteId: bigint,
onImageLoaded: (event: ImageLoadedEvent) => void, onImageLoaded: (event: ImageLoadedEvent) => void,
): Promise<fabric.Canvas> => { ): Promise<fabric.Canvas> => {
const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) }); const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) });