mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Fix clicking the bold button immediately showing the updated button state
- rather than only after typing
This commit is contained in:
parent
bb64f73c1a
commit
2046b00c38
1 changed files with 4 additions and 3 deletions
|
@ -1,9 +1,9 @@
|
||||||
<script lang="typescript" context="module">
|
<script lang="typescript" context="module">
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
export const commandMap = writable(new Map<string, boolean>());
|
const commandMap = writable(new Map<string, boolean>());
|
||||||
|
|
||||||
function initializeButton(key: string): void {
|
function updateButton(key: string): void {
|
||||||
commandMap.update(
|
commandMap.update(
|
||||||
(map: Map<string, boolean>): Map<string, boolean> =>
|
(map: Map<string, boolean>): Map<string, boolean> =>
|
||||||
new Map([...map, [key, document.queryCommandState(key)]])
|
new Map([...map, [key, document.queryCommandState(key)]])
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
if (activatable) {
|
if (activatable) {
|
||||||
initializeButton(command);
|
updateButton(command);
|
||||||
|
|
||||||
commandMap.subscribe((map: Map<string, boolean>): void => {
|
commandMap.subscribe((map: Map<string, boolean>): void => {
|
||||||
active = map.get(command);
|
active = map.get(command);
|
||||||
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
function onClick(): void {
|
function onClick(): void {
|
||||||
document.execCommand(command);
|
document.execCommand(command);
|
||||||
|
updateButton(command);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue