Fix clicking the bold button immediately showing the updated button state

- rather than only after typing
This commit is contained in:
Henrik Giesel 2021-04-03 03:24:22 +02:00
parent bb64f73c1a
commit 2046b00c38

View file

@ -1,9 +1,9 @@
<script lang="typescript" context="module">
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(
(map: Map<string, boolean>): Map<string, boolean> =>
new Map([...map, [key, document.queryCommandState(key)]])
@ -48,7 +48,7 @@
let active = false;
if (activatable) {
initializeButton(command);
updateButton(command);
commandMap.subscribe((map: Map<string, boolean>): void => {
active = map.get(command);
@ -58,6 +58,7 @@
function onClick(): void {
document.execCommand(command);
updateButton(command);
}
</script>