mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -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":
|
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:
|
||||||
gui_hooks.editor_did_fire_typing_timer(self.note)
|
if 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)
|
||||||
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"):
|
elif cmd.startswith("toggleStickyAll"):
|
||||||
model = self.note_type()
|
model = self.note_type()
|
||||||
|
@ -436,7 +440,8 @@ 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"):
|
||||||
gui_hooks.editor_did_update_tags(self.note)
|
if self.note:
|
||||||
|
gui_hooks.editor_did_update_tags(self.note)
|
||||||
|
|
||||||
elif cmd.startswith("editorState"):
|
elif cmd.startswith("editorState"):
|
||||||
(_, new_state_id, old_state_id) = cmd.split(":", 2)
|
(_, 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
|
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)});"
|
||||||
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(
|
self.web.evalWithCallback(
|
||||||
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
|
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
|
||||||
)
|
)
|
||||||
|
|
||||||
@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(
|
||||||
|
|
|
@ -372,28 +372,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
async function noteCanBeAdded(): Promise<boolean> {
|
async function noteCanBeAdded(): Promise<boolean> {
|
||||||
let problem: string | null = null;
|
let problem: string | null = null;
|
||||||
const result = await noteFieldsCheck(note!);
|
const result = await noteFieldsCheck(note!);
|
||||||
if(result.state === NoteFieldsCheckResponse_State.EMPTY) {
|
if (result.state === NoteFieldsCheckResponse_State.EMPTY) {
|
||||||
if(isImageOcclusion) {
|
if (isImageOcclusion) {
|
||||||
problem = tr.notetypesNoOcclusionCreated2();
|
problem = tr.notetypesNoOcclusionCreated2();
|
||||||
} else {
|
} else {
|
||||||
problem = tr.addingTheFirstFieldIsEmpty();
|
problem = tr.addingTheFirstFieldIsEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
|
if (result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
|
||||||
// TODO: askUser(tr.addingYouHaveAClozeDeletionNote())
|
// TODO: askUser(tr.addingYouHaveAClozeDeletionNote())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
|
if (result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
|
||||||
problem = tr.addingClozeOutsideClozeNotetype();
|
problem = tr.addingClozeOutsideClozeNotetype();
|
||||||
}
|
}
|
||||||
if(result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
|
if (result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
|
||||||
problem = tr.addingClozeOutsideClozeField();
|
problem = tr.addingClozeOutsideClozeField();
|
||||||
}
|
}
|
||||||
return problem ? false : true;
|
return problem ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addCurrentNoteInner(deckId: bigint) {
|
async function addCurrentNoteInner(deckId: bigint) {
|
||||||
if(!await noteCanBeAdded()) {
|
if (!(await noteCanBeAdded())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await addNote({
|
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) {
|
export async function addCurrentNote(deckId: bigint) {
|
||||||
if(mode !== "add") {
|
if (mode !== "add") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(isImageOcclusion) {
|
if (isImageOcclusion) {
|
||||||
saveOcclusions();
|
saveOcclusions();
|
||||||
await addCurrentNoteInner(deckId);
|
await addCurrentNoteInner(deckId);
|
||||||
resetIOImageLoaded();
|
resetIOImageLoaded();
|
||||||
|
@ -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!,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) });
|
||||||
|
|
Loading…
Reference in a new issue