Remember last text and highlight color again

This commit is contained in:
Henrik Giesel 2021-08-02 23:12:00 +02:00
parent 355e66e83c
commit 4db7cebf62
5 changed files with 40 additions and 11 deletions

View file

@ -402,6 +402,14 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
return new_state return new_state
elif cmd.startswith("lastTextColor"):
(_, textColor) = cmd.split(":", 1)
self.mw.pm.profile["lastTextColor"] = textColor
elif cmd.startswith("lastHighlightColor"):
(_, highlightColor) = cmd.split(":", 1)
self.mw.pm.profile["lastHighlightColor"] = highlightColor
elif cmd in self._links: elif cmd in self._links:
self._links[cmd](self) self._links[cmd](self)
@ -454,11 +462,15 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
self.web.setFocus() self.web.setFocus()
gui_hooks.editor_did_load_note(self) gui_hooks.editor_did_load_note(self)
js = "setFields(%s); setFonts(%s); focusField(%s); setNoteId(%s);" % ( text_color = self.mw.pm.profile.get("lastTextColor", "#00f")
highlight_color = self.mw.pm.profile.get("lastHighlightColor", "#00f")
js = "setFields(%s); setFonts(%s); focusField(%s); setNoteId(%s); setColorButtons(%s);" % (
json.dumps(data), json.dumps(data),
json.dumps(self.fonts()), json.dumps(self.fonts()),
json.dumps(focusTo), json.dumps(focusTo),
json.dumps(self.note.id), json.dumps(self.note.id),
json.dumps([text_color, highlight_color]),
) )
if self.addMode: if self.addMode:

View file

@ -90,7 +90,8 @@ profileConf: Dict[str, Any] = dict(
lastOptimize=intTime(), lastOptimize=intTime(),
# editing # editing
searchHistory=[], searchHistory=[],
lastColour="#00f", lastTextColor="#00f",
lastHighlightColor="#00f",
# syncing # syncing
syncKey=None, syncKey=None,
syncMedia=True, syncMedia=True,
@ -100,6 +101,7 @@ profileConf: Dict[str, Any] = dict(
importMode=1, importMode=1,
# these are not used, but Anki 2.1.42 and below # these are not used, but Anki 2.1.42 and below
# expect these keys to exist # expect these keys to exist
lastColour="#00f",
stripHTML=True, stripHTML=True,
deleteMedia=False, deleteMedia=False,
) )

View file

@ -13,10 +13,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import WithColorHelper from "./WithColorHelper.svelte"; import WithColorHelper from "./WithColorHelper.svelte";
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { bridgeCommand } from "lib/bridgecommand";
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons"; import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
import { appendInParentheses } from "./helpers"; import { appendInParentheses } from "./helpers";
export let api = {}; export let api = {};
export let textColor: string;
export let highlightColor: string;
$: forecolorWrap = wrapWithForecolor(textColor);
$: backcolorWrap = wrapWithBackcolor(highlightColor);
const wrapWithForecolor = (color: string) => () => { const wrapWithForecolor = (color: string) => () => {
document.execCommand("forecolor", false, color); document.execCommand("forecolor", false, color);
@ -25,15 +31,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const wrapWithBackcolor = (color: string) => () => { const wrapWithBackcolor = (color: string) => () => {
document.execCommand("backcolor", false, color); document.execCommand("backcolor", false, color);
}; };
const initialColor = "black";
let forecolorWrap = wrapWithForecolor(initialColor);
let backcolorWrap = wrapWithForecolor(initialColor);
</script> </script>
<ButtonGroup {api}> <ButtonGroup {api}>
<WithColorHelper color={initialColor} let:colorHelperIcon let:setColor> <WithColorHelper color={textColor} let:colorHelperIcon let:setColor>
<OnlyEditable let:disabled> <OnlyEditable let:disabled>
<ButtonGroupItem> <ButtonGroupItem>
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel> <WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
@ -65,6 +66,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{@html arrowIcon} {@html arrowIcon}
<ColorPicker <ColorPicker
on:change={(event) => { on:change={(event) => {
const textColor = setColor(event);
bridgeCommand(`lastTextColor:${textColor}`);
forecolorWrap = wrapWithForecolor(setColor(event)); forecolorWrap = wrapWithForecolor(setColor(event));
forecolorWrap(); forecolorWrap();
}} }}
@ -76,7 +79,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</OnlyEditable> </OnlyEditable>
</WithColorHelper> </WithColorHelper>
<WithColorHelper color={initialColor} let:colorHelperIcon let:setColor> <WithColorHelper color={highlightColor} let:colorHelperIcon let:setColor>
<OnlyEditable let:disabled> <OnlyEditable let:disabled>
<ButtonGroupItem> <ButtonGroupItem>
<IconButton <IconButton
@ -98,7 +101,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{@html arrowIcon} {@html arrowIcon}
<ColorPicker <ColorPicker
on:change={(event) => { on:change={(event) => {
backcolorWrap = wrapWithBackcolor(setColor(event)); const highlightColor = setColor(event);
bridgeCommand(`lastHighlightColor:${highlightColor}`);
backcolorWrap = wrapWithBackcolor(highlightColor);
backcolorWrap(); backcolorWrap();
}} }}
/> />

View file

@ -40,6 +40,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let size = isApplePlatform() ? 1.6 : 2.0; export let size = isApplePlatform() ? 1.6 : 2.0;
export let wrap = true; export let wrap = true;
export let textColor: string;
export let highlightColor: string;
export const toolbar = {}; export const toolbar = {};
export const notetypeButtons = {}; export const notetypeButtons = {};
export const formatInlineButtons = {}; export const formatInlineButtons = {};
@ -63,7 +66,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</Item> </Item>
<Item id="color"> <Item id="color">
<ColorButtons api={colorButtons} /> <ColorButtons {textColor} {highlightColor} api={colorButtons} />
</Item> </Item>
<Item id="template"> <Item id="template">

View file

@ -3,6 +3,7 @@
/* eslint /* eslint
@typescript-eslint/no-non-null-assertion: "off", @typescript-eslint/no-non-null-assertion: "off",
@typescript-eslint/no-explicit-any: "off",
*/ */
import { filterHTML } from "html-filter"; import { filterHTML } from "html-filter";
@ -169,6 +170,12 @@ export function setFonts(fonts: [string, number, boolean][]): void {
); );
} }
export function setColorButtons([textColor, highlightColor]: [string, string]): void {
$editorToolbar.then((editorToolbar) =>
(editorToolbar as any).$set({ textColor, highlightColor })
);
}
export function setSticky(stickies: boolean[]): void { export function setSticky(stickies: boolean[]): void {
forEditorField(stickies, (field: EditorField, isSticky: boolean) => { forEditorField(stickies, (field: EditorField, isSticky: boolean) => {
field.labelContainer.activateSticky(isSticky); field.labelContainer.activateSticky(isSticky);