mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Fix undo ops of add_note/update_notetype
This commit is contained in:
parent
5a7832b16d
commit
dbd8737f0a
4 changed files with 27 additions and 12 deletions
|
@ -11,6 +11,7 @@ import "anki/scheduler.proto";
|
|||
import "anki/generic.proto";
|
||||
import "anki/search.proto";
|
||||
import "anki/notes.proto";
|
||||
import "anki/notetypes.proto";
|
||||
|
||||
service FrontendService {
|
||||
// Returns values from the reviewer
|
||||
|
@ -31,6 +32,8 @@ service FrontendService {
|
|||
|
||||
// Editor
|
||||
rpc EditorUpdateNote(notes.UpdateNotesRequest) returns (generic.Empty);
|
||||
rpc EditorUpdateNotetype(notetypes.Notetype) returns (generic.Empty);
|
||||
rpc EditorAddNote(notes.AddNoteRequest) returns (generic.Empty);
|
||||
rpc ConvertPastedImage(ConvertPastedImageRequest)
|
||||
returns (ConvertPastedImageResponse);
|
||||
rpc RetrieveUrl(generic.String) returns (RetrieveUrlResponse);
|
||||
|
|
|
@ -602,14 +602,14 @@ def deck_options_ready() -> bytes:
|
|||
return b""
|
||||
|
||||
|
||||
def editor_update_note() -> bytes:
|
||||
from aqt.editor import Editor
|
||||
|
||||
output = raw_backend_request("update_notes")()
|
||||
def editor_op_changes_request(endpoint: str) -> bytes:
|
||||
output = raw_backend_request(endpoint)()
|
||||
response = OpChanges()
|
||||
response.ParseFromString(output)
|
||||
|
||||
def handle_on_main() -> None:
|
||||
from aqt.editor import Editor
|
||||
|
||||
handler = aqt.mw.app.activeWindow()
|
||||
if handler and isinstance(getattr(handler, "editor", None), Editor):
|
||||
handler = handler.editor # type: ignore
|
||||
|
@ -620,6 +620,18 @@ def editor_update_note() -> bytes:
|
|||
return output
|
||||
|
||||
|
||||
def editor_update_note() -> bytes:
|
||||
return editor_op_changes_request("update_notes")
|
||||
|
||||
|
||||
def editor_update_notetype() -> bytes:
|
||||
return editor_op_changes_request("update_notetype")
|
||||
|
||||
|
||||
def editor_add_note() -> bytes:
|
||||
return editor_op_changes_request("add_note")
|
||||
|
||||
|
||||
def get_setting_json(getter: Callable[[str], Any]) -> bytes:
|
||||
req = generic_pb2.String()
|
||||
req.ParseFromString(request.data)
|
||||
|
@ -822,6 +834,8 @@ post_handler_list = [
|
|||
deck_options_require_close,
|
||||
deck_options_ready,
|
||||
editor_update_note,
|
||||
editor_update_notetype,
|
||||
editor_add_note,
|
||||
get_profile_config_json,
|
||||
set_profile_config_json,
|
||||
get_meta_json,
|
||||
|
@ -854,13 +868,11 @@ exposed_backend_list = [
|
|||
"get_note",
|
||||
"new_note",
|
||||
"note_fields_check",
|
||||
"add_note",
|
||||
# NotetypesService
|
||||
"get_notetype",
|
||||
"get_notetype_names",
|
||||
"get_change_notetype_info",
|
||||
"get_cloze_field_ords",
|
||||
"update_notetype",
|
||||
# StatsService
|
||||
"card_stats",
|
||||
"get_review_logs",
|
||||
|
|
|
@ -225,7 +225,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
}
|
||||
values.push(field.config!.sticky);
|
||||
}
|
||||
await updateNotetype(notetype);
|
||||
await editorUpdateNotetype(notetype);
|
||||
setSticky(values);
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
if (!(await noteCanBeAdded())) {
|
||||
return;
|
||||
}
|
||||
await addNote({
|
||||
await editorAddNote({
|
||||
note: note!,
|
||||
deckId,
|
||||
});
|
||||
|
@ -584,9 +584,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
editorUpdateNote,
|
||||
decodeIriPaths,
|
||||
noteFieldsCheck,
|
||||
addNote,
|
||||
editorAddNote,
|
||||
addMediaFromPath,
|
||||
updateNotetype,
|
||||
editorUpdateNotetype,
|
||||
closeAddCards as closeAddCardsBackend,
|
||||
} from "@generated/backend";
|
||||
import { wrapInternal } from "@tslib/wrap";
|
||||
|
|
|
@ -15,7 +15,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
import { context as editorFieldContext } from "./EditorField.svelte";
|
||||
import type { Note } from "@generated/anki/notes_pb";
|
||||
import { getNotetype, updateNotetype } from "@generated/backend";
|
||||
import { getNotetype, editorUpdateNotetype } from "@generated/backend";
|
||||
|
||||
const animated = !document.body.classList.contains("reduce-motion");
|
||||
|
||||
|
@ -32,7 +32,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
active = !active;
|
||||
const notetype = await getNotetype({ ntid: note.notetypeId });
|
||||
notetype.fields[index].config!.sticky = active;
|
||||
await updateNotetype(notetype);
|
||||
await editorUpdateNotetype(notetype);
|
||||
}
|
||||
|
||||
function shortcut(target: HTMLElement): () => void {
|
||||
|
|
Loading…
Reference in a new issue