Skip to content

Commit b800574

Browse files
Fix visual behavior of modal buttons in editor (#3009)
* Fix behavior of justification buttons * Make list buttons update each other when clicked
1 parent 2b4cb29 commit b800574

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ts/editor/editor-toolbar/BlockButtons.svelte

+15
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
7777
}
7878
7979
const rtl = window.getComputedStyle(document.body).direction === "rtl";
80+
81+
const justificationKeys = [
82+
"justifyLeft",
83+
"justifyCenter",
84+
"justifyRight",
85+
"justifyFull",
86+
];
87+
88+
const listKeys = ["insertUnorderedList", "insertOrderedList"];
8089
</script>
8190

8291
<ButtonGroup>
@@ -92,6 +101,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
92101
key="insertUnorderedList"
93102
tooltip={tr.editingUnorderedList()}
94103
shortcut="Control+,"
104+
modeVariantKeys={listKeys}
95105
>
96106
{@html ulIcon}
97107
</CommandIconButton>
@@ -102,6 +112,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
102112
key="insertOrderedList"
103113
tooltip={tr.editingOrderedList()}
104114
shortcut="Control+."
115+
modeVariantKeys={listKeys}
105116
>
106117
{@html olIcon}
107118
</CommandIconButton>
@@ -138,6 +149,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
138149
<CommandIconButton
139150
key="justifyLeft"
140151
tooltip={tr.editingAlignLeft()}
152+
modeVariantKeys={justificationKeys}
141153
>
142154
{@html justifyLeftIcon}
143155
</CommandIconButton>
@@ -147,6 +159,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
147159
<CommandIconButton
148160
key="justifyCenter"
149161
tooltip={tr.editingCenter()}
162+
modeVariantKeys={justificationKeys}
150163
>
151164
{@html justifyCenterIcon}
152165
</CommandIconButton>
@@ -156,6 +169,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
156169
<CommandIconButton
157170
key="justifyRight"
158171
tooltip={tr.editingAlignRight()}
172+
modeVariantKeys={justificationKeys}
159173
>
160174
{@html justifyRightIcon}
161175
</CommandIconButton>
@@ -165,6 +179,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
165179
<CommandIconButton
166180
key="justifyFull"
167181
tooltip={tr.editingJustify()}
182+
modeVariantKeys={justificationKeys}
168183
>
169184
{@html justifyFullIcon}
170185
</CommandIconButton>

ts/editor/editor-toolbar/CommandIconButton.svelte

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
88
import IconButton from "../../components/IconButton.svelte";
99
import Shortcut from "../../components/Shortcut.svelte";
1010
import WithState from "../../components/WithState.svelte";
11+
import { updateStateByKey } from "../../components/WithState.svelte";
1112
import { execCommand, queryCommandState } from "../../domlib";
1213
import { context as noteEditorContext } from "../NoteEditor.svelte";
1314
import { editingInputIsRichText } from "../rich-text-input";
1415
1516
export let key: string;
1617
export let tooltip: string;
1718
export let shortcut: string | null = null;
19+
export let modeVariantKeys: string[] = [key];
1820
1921
$: theTooltip = shortcut ? `${tooltip} (${getPlatformString(shortcut)})` : tooltip;
2022
@@ -38,19 +40,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
3840
<Shortcut keyCombination={shortcut} on:action={action} />
3941
{/if}
4042
{:else}
41-
<WithState
42-
{key}
43-
update={async () => queryCommandState(key)}
44-
let:state={active}
45-
let:updateState
46-
>
43+
<WithState {key} update={async () => queryCommandState(key)} let:state={active}>
4744
<IconButton
4845
tooltip={theTooltip}
4946
{active}
5047
{disabled}
5148
on:click={(event) => {
5249
action();
53-
updateState(event);
50+
modeVariantKeys.map((key) => updateStateByKey(key, event));
5451
}}
5552
>
5653
<slot />
@@ -61,7 +58,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
6158
keyCombination={shortcut}
6259
on:action={(event) => {
6360
action();
64-
updateState(event);
61+
modeVariantKeys.map((key) => updateStateByKey(key, event));
6562
}}
6663
/>
6764
{/if}

0 commit comments

Comments
 (0)