From 5e550b24c562a0fc35a734e99281a8f823ecbf15 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 22 Sep 2021 05:07:25 -0400 Subject: fixes for fontcolor dropdown to be continuous as pointer moves. --- src/client/views/nodes/button/FontIconBox.tsx | 43 +++++++++++----------- .../views/nodes/formattedText/RichTextMenu.tsx | 3 +- 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx index 6a782b105..368699dea 100644 --- a/src/client/views/nodes/button/FontIconBox.tsx +++ b/src/client/views/nodes/button/FontIconBox.tsx @@ -318,27 +318,33 @@ export class FontIconBox extends DocComponent(Fon ); } + @computed get colorScript() { + const script = StrCast(this.rootDoc.script); + return ScriptField.MakeScript(script + '(colValue, checkResult)', { colValue: "string", checkResult: "boolean" }); + } + colorPicker = (boolResult: string) => { + const click = (value: ColorState) => { + const s = this.colorScript; + s && undoBatch(() => s.script.run({ colValue: Utils.colorString(value), checkResult: false }).result)(); + }; + const colorOptions: string[] = ['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', + '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', + '#FFFFFF', '#f1efeb', "transparent"]; + return ; + } /** * Color button */ @computed get colorButton() { - const active: string = StrCast(this.rootDoc.dropDownOpen); + const active = StrCast(this.rootDoc.dropDownOpen); const color = this.props.styleProvider?.(this.rootDoc, this.props, StyleProp.Color); const backgroundColor = this.props.styleProvider?.(this.rootDoc, this.props, StyleProp.BackgroundColor); + const boolResult = this.colorScript?.script.run({ colValue: undefined, checkResult: true }).result; - const script: string = StrCast(this.rootDoc.script); - const scriptCheck: string = script + "(undefined, true)"; - const boolResult = ScriptField.MakeScript(scriptCheck)?.script.run().result; - - const colorOptions: string[] = ['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', - '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', - '#FFFFFF', '#f1efeb', "transparent"]; - - const colorBox = (func: (color: ColorState) => void) => ; const label = !this.label || !Doc.UserDoc()._showLabel ? (null) :
{this.label} @@ -350,10 +356,6 @@ export class FontIconBox extends DocComponent(Fon
; - const click = (value: ColorState) => { - const s = ScriptField.MakeScript(script + '("' + Utils.colorString(value) + '", false)'); - s && undoBatch(() => s.script.run().result)(); - }; return (
(Fon
e.stopPropagation()} onClick={e => e.stopPropagation()}> - {colorBox(click)} + {this.colorPicker(boolResult ?? "transparent")}
{ e.stopPropagation(); this.rootDoc.dropDownOpen = false; }} />
@@ -574,7 +576,6 @@ Scripting.addGlobal(function setBackgroundColor(color?: string, checkResult?: bo return selected?._backgroundColor ?? "transparent"; } if (selected) selected._backgroundColor = color; - Doc.UserDoc()._fontColor = color; }); // toggle: Set overlay status of selected document @@ -683,7 +684,7 @@ Scripting.addGlobal(function setFontColor(color?: string, checkResult?: boolean) } if (editorView) color && RichTextMenu.Instance.setColor(color, editorView, editorView?.dispatch); - else Doc.UserDoc()._fontColor = color; + else Doc.UserDoc().fontColor = color; }); // toggle: Set overlay status of selected document diff --git a/src/client/views/nodes/formattedText/RichTextMenu.tsx b/src/client/views/nodes/formattedText/RichTextMenu.tsx index 0a2a54aae..3efc46259 100644 --- a/src/client/views/nodes/formattedText/RichTextMenu.tsx +++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx @@ -336,8 +336,9 @@ export class RichTextMenu extends AntimodeMenu { setColor(color: String, view: EditorView, dispatch: any) { if (this.view) { const colorMark = view.state.schema.mark(view.state.schema.marks.pFontColor, { color }); - view.focus(); this.setMark(colorMark, this.view.state, (tx: any) => this.view!.dispatch(tx.addStoredMark(colorMark)), true); + view.focus(); + this.updateMenu(this.view, undefined, this.props); } } -- cgit v1.2.3-70-g09d2