Merge pull request #1320 from hgiesel/colorpickerplus
Remember last text and highlight color again
This commit is contained in:
commit
87f9bd8021
@ -402,6 +402,14 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
|
||||
|
||||
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:
|
||||
self._links[cmd](self)
|
||||
|
||||
@ -454,11 +462,15 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
|
||||
self.web.setFocus()
|
||||
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(self.fonts()),
|
||||
json.dumps(focusTo),
|
||||
json.dumps(self.note.id),
|
||||
json.dumps([text_color, highlight_color]),
|
||||
)
|
||||
|
||||
if self.addMode:
|
||||
|
@ -90,7 +90,8 @@ profileConf: Dict[str, Any] = dict(
|
||||
lastOptimize=intTime(),
|
||||
# editing
|
||||
searchHistory=[],
|
||||
lastColour="#00f",
|
||||
lastTextColor="#00f",
|
||||
lastHighlightColor="#00f",
|
||||
# syncing
|
||||
syncKey=None,
|
||||
syncMedia=True,
|
||||
@ -100,6 +101,7 @@ profileConf: Dict[str, Any] = dict(
|
||||
importMode=1,
|
||||
# these are not used, but Anki 2.1.42 and below
|
||||
# expect these keys to exist
|
||||
lastColour="#00f",
|
||||
stripHTML=True,
|
||||
deleteMedia=False,
|
||||
)
|
||||
|
@ -13,10 +13,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import WithColorHelper from "./WithColorHelper.svelte";
|
||||
import OnlyEditable from "./OnlyEditable.svelte";
|
||||
|
||||
import { bridgeCommand } from "lib/bridgecommand";
|
||||
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
|
||||
import { appendInParentheses } from "./helpers";
|
||||
|
||||
export let api = {};
|
||||
export let textColor: string;
|
||||
export let highlightColor: string;
|
||||
|
||||
$: forecolorWrap = wrapWithForecolor(textColor);
|
||||
$: backcolorWrap = wrapWithBackcolor(highlightColor);
|
||||
|
||||
const wrapWithForecolor = (color: string) => () => {
|
||||
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) => () => {
|
||||
document.execCommand("backcolor", false, color);
|
||||
};
|
||||
|
||||
const initialColor = "black";
|
||||
|
||||
let forecolorWrap = wrapWithForecolor(initialColor);
|
||||
let backcolorWrap = wrapWithForecolor(initialColor);
|
||||
</script>
|
||||
|
||||
<ButtonGroup {api}>
|
||||
<WithColorHelper color={initialColor} let:colorHelperIcon let:setColor>
|
||||
<WithColorHelper color={textColor} let:colorHelperIcon let:setColor>
|
||||
<OnlyEditable let:disabled>
|
||||
<ButtonGroupItem>
|
||||
<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}
|
||||
<ColorPicker
|
||||
on:change={(event) => {
|
||||
const textColor = setColor(event);
|
||||
bridgeCommand(`lastTextColor:${textColor}`);
|
||||
forecolorWrap = wrapWithForecolor(setColor(event));
|
||||
forecolorWrap();
|
||||
}}
|
||||
@ -76,7 +79,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
</OnlyEditable>
|
||||
</WithColorHelper>
|
||||
|
||||
<WithColorHelper color={initialColor} let:colorHelperIcon let:setColor>
|
||||
<WithColorHelper color={highlightColor} let:colorHelperIcon let:setColor>
|
||||
<OnlyEditable let:disabled>
|
||||
<ButtonGroupItem>
|
||||
<IconButton
|
||||
@ -98,7 +101,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
{@html arrowIcon}
|
||||
<ColorPicker
|
||||
on:change={(event) => {
|
||||
backcolorWrap = wrapWithBackcolor(setColor(event));
|
||||
const highlightColor = setColor(event);
|
||||
bridgeCommand(`lastHighlightColor:${highlightColor}`);
|
||||
backcolorWrap = wrapWithBackcolor(highlightColor);
|
||||
backcolorWrap();
|
||||
}}
|
||||
/>
|
||||
|
@ -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 wrap = true;
|
||||
|
||||
export let textColor: string;
|
||||
export let highlightColor: string;
|
||||
|
||||
export const toolbar = {};
|
||||
export const notetypeButtons = {};
|
||||
export const formatInlineButtons = {};
|
||||
@ -63,7 +66,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
</Item>
|
||||
|
||||
<Item id="color">
|
||||
<ColorButtons api={colorButtons} />
|
||||
<ColorButtons {textColor} {highlightColor} api={colorButtons} />
|
||||
</Item>
|
||||
|
||||
<Item id="template">
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
/* eslint
|
||||
@typescript-eslint/no-non-null-assertion: "off",
|
||||
@typescript-eslint/no-explicit-any: "off",
|
||||
*/
|
||||
|
||||
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 {
|
||||
forEditorField(stickies, (field: EditorField, isSticky: boolean) => {
|
||||
field.labelContainer.activateSticky(isSticky);
|
||||
|
Loading…
Reference in New Issue
Block a user