mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
Fix lint errors
This commit is contained in:
parent
05360e2d19
commit
07d3b6d2b5
6 changed files with 28 additions and 21 deletions
|
@ -387,20 +387,24 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
if type == "blur":
|
||||
self.currentField = None
|
||||
# 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
|
||||
# event has had time to fire
|
||||
self.mw.progress.timer(
|
||||
100, self.loadNoteKeepingFocus, False, parent=self.widget
|
||||
)
|
||||
else:
|
||||
gui_hooks.editor_did_fire_typing_timer(self.note)
|
||||
if self.note:
|
||||
gui_hooks.editor_did_fire_typing_timer(self.note)
|
||||
|
||||
# focused into field?
|
||||
elif cmd.startswith("focus"):
|
||||
(type, num) = cmd.split(":", 1)
|
||||
self.last_field_index = self.currentField = int(num)
|
||||
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||
if self.note:
|
||||
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||
|
||||
elif cmd.startswith("toggleStickyAll"):
|
||||
model = self.note_type()
|
||||
|
@ -436,7 +440,8 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
return new_state
|
||||
|
||||
elif cmd.startswith("saveTags"):
|
||||
gui_hooks.editor_did_update_tags(self.note)
|
||||
if self.note:
|
||||
gui_hooks.editor_did_update_tags(self.note)
|
||||
|
||||
elif cmd.startswith("editorState"):
|
||||
(_, new_state_id, old_state_id) = cmd.split(":", 2)
|
||||
|
@ -516,13 +521,15 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
|||
|
||||
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 = gui_hooks.editor_will_load_note(js, self.note, self)
|
||||
if self.note:
|
||||
js = gui_hooks.editor_will_load_note(js, self.note, self)
|
||||
self.web.evalWithCallback(
|
||||
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
|
||||
)
|
||||
|
||||
@deprecated(replaced_by=load_note)
|
||||
def loadNote(self, focusTo: int | None = None) -> None:
|
||||
assert self.note is not None
|
||||
self.load_note(self.note.mid, focus_to=focusTo)
|
||||
|
||||
def call_after_note_saved(
|
||||
|
|
|
@ -372,28 +372,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
async function noteCanBeAdded(): Promise<boolean> {
|
||||
let problem: string | null = null;
|
||||
const result = await noteFieldsCheck(note!);
|
||||
if(result.state === NoteFieldsCheckResponse_State.EMPTY) {
|
||||
if(isImageOcclusion) {
|
||||
if (result.state === NoteFieldsCheckResponse_State.EMPTY) {
|
||||
if (isImageOcclusion) {
|
||||
problem = tr.notetypesNoOcclusionCreated2();
|
||||
} else {
|
||||
problem = tr.addingTheFirstFieldIsEmpty();
|
||||
}
|
||||
}
|
||||
if(result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
|
||||
if (result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
|
||||
// TODO: askUser(tr.addingYouHaveAClozeDeletionNote())
|
||||
return false;
|
||||
}
|
||||
if(result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
|
||||
if (result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
|
||||
problem = tr.addingClozeOutsideClozeNotetype();
|
||||
}
|
||||
if(result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
|
||||
if (result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
|
||||
problem = tr.addingClozeOutsideClozeField();
|
||||
}
|
||||
return problem ? false : true;
|
||||
}
|
||||
|
||||
async function addCurrentNoteInner(deckId: bigint) {
|
||||
if(!await noteCanBeAdded()) {
|
||||
if (!(await noteCanBeAdded())) {
|
||||
return;
|
||||
}
|
||||
await addNote({
|
||||
|
@ -404,10 +404,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
}
|
||||
|
||||
export async function addCurrentNote(deckId: bigint) {
|
||||
if(mode !== "add") {
|
||||
if (mode !== "add") {
|
||||
return;
|
||||
}
|
||||
if(isImageOcclusion) {
|
||||
if (isImageOcclusion) {
|
||||
saveOcclusions();
|
||||
await addCurrentNoteInner(deckId);
|
||||
resetIOImageLoaded();
|
||||
|
@ -679,7 +679,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
} else {
|
||||
setNote(
|
||||
await getNote({
|
||||
nid!,
|
||||
nid: nid!,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ async function save(): Promise<void> {
|
|||
export const load = (async ({ params }) => {
|
||||
let mode: IOMode;
|
||||
if (/^\d+/.test(params.imagePathOrNoteId)) {
|
||||
mode = { kind: "edit", noteId: Number(params.imagePathOrNoteId) };
|
||||
mode = { kind: "edit", noteId: BigInt(params.imagePathOrNoteId) };
|
||||
} else {
|
||||
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 };
|
||||
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0n };
|
||||
}
|
||||
|
||||
// for adding note from mobile devices
|
||||
|
|
|
@ -31,7 +31,7 @@ export const addOrUpdateNote = async function(
|
|||
|
||||
if (mode.kind == "edit") {
|
||||
const result = await updateImageOcclusionNote({
|
||||
noteId: BigInt(mode.noteId),
|
||||
noteId: mode.noteId,
|
||||
occlusions: occlusionCloze,
|
||||
header,
|
||||
backExtra,
|
||||
|
@ -53,7 +53,7 @@ export const addOrUpdateNote = async function(
|
|||
};
|
||||
|
||||
// show toast message
|
||||
const showResult = (noteId: number | null, result: OpChanges, count: number) => {
|
||||
const showResult = (noteId: bigint | null, result: OpChanges, count: number) => {
|
||||
const props = $state({
|
||||
message: "",
|
||||
type: "error" as "error" | "success",
|
||||
|
|
|
@ -50,10 +50,10 @@ export async function setupImageOcclusion(mode: IOMode, target = document.body):
|
|||
|
||||
if (window.location.hash.startsWith("#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-")) {
|
||||
const noteId = parseInt(window.location.hash.replace("#testforedit-", ""));
|
||||
const noteId = BigInt(window.location.hash.replace("#testforedit-", ""));
|
||||
setupImageOcclusion({ kind: "edit", noteId });
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ export const setupMaskEditor = async (
|
|||
};
|
||||
|
||||
export const setupMaskEditorForEdit = async (
|
||||
noteId: number,
|
||||
noteId: bigint,
|
||||
onImageLoaded: (event: ImageLoadedEvent) => void,
|
||||
): Promise<fabric.Canvas> => {
|
||||
const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) });
|
||||
|
|
Loading…
Reference in a new issue