mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Move IO/cloze button toggles
This commit is contained in:
parent
07d3b6d2b5
commit
545d3dbfed
3 changed files with 22 additions and 23 deletions
|
@ -1310,25 +1310,3 @@ class EditorWebView(AnkiWebView):
|
|||
clipboard = self.editor.mw.app.clipboard()
|
||||
assert clipboard is not None
|
||||
return clipboard
|
||||
|
||||
|
||||
def set_cloze_button(editor: Editor) -> None:
|
||||
action = "show" if editor.note_type()["type"] == MODEL_CLOZE else "hide"
|
||||
editor.web.eval(
|
||||
'require("anki/ui").loaded.then(() =>'
|
||||
f'require("anki/NoteEditor").instances[0].toolbar.toolbar.{action}("cloze")'
|
||||
"); "
|
||||
)
|
||||
|
||||
|
||||
def set_image_occlusion_button(editor: Editor) -> None:
|
||||
action = "show" if editor.current_notetype_is_image_occlusion() else "hide"
|
||||
editor.web.eval(
|
||||
'require("anki/ui").loaded.then(() =>'
|
||||
f'require("anki/NoteEditor").instances[0].toolbar.toolbar.{action}("image-occlusion-button")'
|
||||
"); "
|
||||
)
|
||||
|
||||
|
||||
gui_hooks.editor_did_load_note.append(set_cloze_button)
|
||||
gui_hooks.editor_did_load_note.append(set_image_occlusion_button)
|
||||
|
|
|
@ -240,6 +240,7 @@ export interface DefaultSlotInterface extends Record<string, unknown> {
|
|||
show(position: Identifier): Promise<boolean>;
|
||||
hide(position: Identifier): Promise<boolean>;
|
||||
toggle(position: Identifier): Promise<boolean>;
|
||||
setShown(position: Identifier, shown: boolean): Promise<boolean>;
|
||||
}
|
||||
|
||||
export function defaultInterface<T extends SlotHostProps, U extends Element>({
|
||||
|
@ -287,12 +288,20 @@ export function defaultInterface<T extends SlotHostProps, U extends Element>({
|
|||
}, id);
|
||||
}
|
||||
|
||||
function setShown(id: Identifier, shown: boolean): Promise<boolean> {
|
||||
return updateProps((props: T): T => {
|
||||
props.detach.set(!shown);
|
||||
return props;
|
||||
}, id);
|
||||
}
|
||||
|
||||
return {
|
||||
insert,
|
||||
append,
|
||||
show,
|
||||
hide,
|
||||
toggle,
|
||||
setShown,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -503,7 +503,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
import { ImageOcclusionFieldIndexes } from "@generated/anki/image_occlusion_pb";
|
||||
|
||||
import { StockNotetype_OriginalStockKind } from "@generated/anki/notetypes_pb";
|
||||
import {
|
||||
Notetype_Config_Kind,
|
||||
StockNotetype_OriginalStockKind,
|
||||
} from "@generated/anki/notetypes_pb";
|
||||
import type { Notetype } from "@generated/anki/notetypes_pb";
|
||||
import {
|
||||
getFieldNames,
|
||||
|
@ -715,6 +718,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
);
|
||||
focusField(focusTo);
|
||||
toolbar.inlineButtons?.setColorButtons([lastTextColor, lastHighlightColor]);
|
||||
await toolbar.toolbar?.setShown(
|
||||
"image-occlusion-button",
|
||||
notetype.config?.originalStockKind ===
|
||||
StockNotetype_OriginalStockKind.IMAGE_OCCLUSION,
|
||||
);
|
||||
await toolbar.toolbar?.setShown(
|
||||
"cloze",
|
||||
notetype.config?.kind === Notetype_Config_Kind.CLOZE,
|
||||
);
|
||||
setTags(tags);
|
||||
setTagsCollapsed(await getMeta(tagsCollapsedMetaKey));
|
||||
setMathjaxEnabled((await getColConfig("renderMathjax")) ?? true);
|
||||
|
|
Loading…
Reference in a new issue