mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix visual behavior of modal buttons in editor (#3009)
* Fix behavior of justification buttons * Make list buttons update each other when clicked
This commit is contained in:
parent
2b4cb2992b
commit
b80057440e
2 changed files with 20 additions and 8 deletions
|
@ -77,6 +77,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
const rtl = window.getComputedStyle(document.body).direction === "rtl";
|
const rtl = window.getComputedStyle(document.body).direction === "rtl";
|
||||||
|
|
||||||
|
const justificationKeys = [
|
||||||
|
"justifyLeft",
|
||||||
|
"justifyCenter",
|
||||||
|
"justifyRight",
|
||||||
|
"justifyFull",
|
||||||
|
];
|
||||||
|
|
||||||
|
const listKeys = ["insertUnorderedList", "insertOrderedList"];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
|
@ -92,6 +101,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
key="insertUnorderedList"
|
key="insertUnorderedList"
|
||||||
tooltip={tr.editingUnorderedList()}
|
tooltip={tr.editingUnorderedList()}
|
||||||
shortcut="Control+,"
|
shortcut="Control+,"
|
||||||
|
modeVariantKeys={listKeys}
|
||||||
>
|
>
|
||||||
{@html ulIcon}
|
{@html ulIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
@ -102,6 +112,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
key="insertOrderedList"
|
key="insertOrderedList"
|
||||||
tooltip={tr.editingOrderedList()}
|
tooltip={tr.editingOrderedList()}
|
||||||
shortcut="Control+."
|
shortcut="Control+."
|
||||||
|
modeVariantKeys={listKeys}
|
||||||
>
|
>
|
||||||
{@html olIcon}
|
{@html olIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
@ -138,6 +149,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<CommandIconButton
|
<CommandIconButton
|
||||||
key="justifyLeft"
|
key="justifyLeft"
|
||||||
tooltip={tr.editingAlignLeft()}
|
tooltip={tr.editingAlignLeft()}
|
||||||
|
modeVariantKeys={justificationKeys}
|
||||||
>
|
>
|
||||||
{@html justifyLeftIcon}
|
{@html justifyLeftIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
@ -147,6 +159,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<CommandIconButton
|
<CommandIconButton
|
||||||
key="justifyCenter"
|
key="justifyCenter"
|
||||||
tooltip={tr.editingCenter()}
|
tooltip={tr.editingCenter()}
|
||||||
|
modeVariantKeys={justificationKeys}
|
||||||
>
|
>
|
||||||
{@html justifyCenterIcon}
|
{@html justifyCenterIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
@ -156,6 +169,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<CommandIconButton
|
<CommandIconButton
|
||||||
key="justifyRight"
|
key="justifyRight"
|
||||||
tooltip={tr.editingAlignRight()}
|
tooltip={tr.editingAlignRight()}
|
||||||
|
modeVariantKeys={justificationKeys}
|
||||||
>
|
>
|
||||||
{@html justifyRightIcon}
|
{@html justifyRightIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
@ -165,6 +179,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<CommandIconButton
|
<CommandIconButton
|
||||||
key="justifyFull"
|
key="justifyFull"
|
||||||
tooltip={tr.editingJustify()}
|
tooltip={tr.editingJustify()}
|
||||||
|
modeVariantKeys={justificationKeys}
|
||||||
>
|
>
|
||||||
{@html justifyFullIcon}
|
{@html justifyFullIcon}
|
||||||
</CommandIconButton>
|
</CommandIconButton>
|
||||||
|
|
|
@ -8,6 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import IconButton from "../../components/IconButton.svelte";
|
import IconButton from "../../components/IconButton.svelte";
|
||||||
import Shortcut from "../../components/Shortcut.svelte";
|
import Shortcut from "../../components/Shortcut.svelte";
|
||||||
import WithState from "../../components/WithState.svelte";
|
import WithState from "../../components/WithState.svelte";
|
||||||
|
import { updateStateByKey } from "../../components/WithState.svelte";
|
||||||
import { execCommand, queryCommandState } from "../../domlib";
|
import { execCommand, queryCommandState } from "../../domlib";
|
||||||
import { context as noteEditorContext } from "../NoteEditor.svelte";
|
import { context as noteEditorContext } from "../NoteEditor.svelte";
|
||||||
import { editingInputIsRichText } from "../rich-text-input";
|
import { editingInputIsRichText } from "../rich-text-input";
|
||||||
|
@ -15,6 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let key: string;
|
export let key: string;
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
export let shortcut: string | null = null;
|
export let shortcut: string | null = null;
|
||||||
|
export let modeVariantKeys: string[] = [key];
|
||||||
|
|
||||||
$: theTooltip = shortcut ? `${tooltip} (${getPlatformString(shortcut)})` : tooltip;
|
$: theTooltip = shortcut ? `${tooltip} (${getPlatformString(shortcut)})` : tooltip;
|
||||||
|
|
||||||
|
@ -38,19 +40,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<Shortcut keyCombination={shortcut} on:action={action} />
|
<Shortcut keyCombination={shortcut} on:action={action} />
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<WithState
|
<WithState {key} update={async () => queryCommandState(key)} let:state={active}>
|
||||||
{key}
|
|
||||||
update={async () => queryCommandState(key)}
|
|
||||||
let:state={active}
|
|
||||||
let:updateState
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={theTooltip}
|
tooltip={theTooltip}
|
||||||
{active}
|
{active}
|
||||||
{disabled}
|
{disabled}
|
||||||
on:click={(event) => {
|
on:click={(event) => {
|
||||||
action();
|
action();
|
||||||
updateState(event);
|
modeVariantKeys.map((key) => updateStateByKey(key, event));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -61,7 +58,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
keyCombination={shortcut}
|
keyCombination={shortcut}
|
||||||
on:action={(event) => {
|
on:action={(event) => {
|
||||||
action();
|
action();
|
||||||
updateState(event);
|
modeVariantKeys.map((key) => updateStateByKey(key, event));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in a new issue