Port Focus tags shortcut to webview

This commit is contained in:
Henrik Giesel 2021-06-24 16:44:08 +02:00
parent f3df0fe305
commit f056851c1e
15 changed files with 68 additions and 42 deletions

View file

@ -300,9 +300,7 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
def setupShortcuts(self) -> None: def setupShortcuts(self) -> None:
# if a third element is provided, enable shortcut even when no field selected # if a third element is provided, enable shortcut even when no field selected
cuts: List[Tuple] = [ cuts: List[Tuple] = []
("Ctrl+Shift+T", self.onFocusTags, True),
]
gui_hooks.editor_did_init_shortcuts(cuts, self) gui_hooks.editor_did_init_shortcuts(cuts, self)
for row in cuts: for row in cuts:
if len(row) == 2: if len(row) == 2:

View file

@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts"> <script lang="ts">
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import type { ChangeNotetypeState } from "./lib"; import type { ChangeNotetypeState } from "./lib";
import { withButton } from "components/helpers";
import ButtonGroup from "components/ButtonGroup.svelte"; import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte"; import ButtonGroupItem from "components/ButtonGroupItem.svelte";
@ -29,9 +30,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
theme="primary" theme="primary"
on:click={() => save()} on:click={() => save()}
tooltip={shortcutLabel} tooltip={shortcutLabel}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
>{tr.actionsSave()}</LabelButton >{tr.actionsSave()}</LabelButton>
>
</WithShortcut> </WithShortcut>
</ButtonGroupItem> </ButtonGroupItem>
</ButtonGroup> </ButtonGroup>

View file

@ -9,6 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let className = ""; let className = "";
export { className as class }; export { className as class };
export let tooltip: string | undefined;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@ -23,6 +24,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<span <span
bind:this={spanRef} bind:this={spanRef}
title={tooltip}
class={`badge ${className}`} class={`badge ${className}`}
class:dropdown-toggle={dropdownProps.dropdown} class:dropdown-toggle={dropdownProps.dropdown}
{...dropdownProps} {...dropdownProps}

View file

@ -12,9 +12,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let deregister: () => void; let deregister: () => void;
function createShortcut(mounted: HTMLElement): void { function createShortcut(element: HTMLElement): void {
deregister = registerShortcut((event: KeyboardEvent) => { deregister = registerShortcut((event: KeyboardEvent) => {
mounted.dispatchEvent(new MouseEvent("click", event)); element.dispatchEvent(new MouseEvent("click", event));
event.preventDefault(); event.preventDefault();
}, shortcut); }, shortcut);
} }

View file

@ -14,3 +14,15 @@ export function mergeTooltipAndShortcut(
} }
return buf; return buf;
} }
export const withButton =
(f: (button: HTMLButtonElement) => void) =>
({ detail }: CustomEvent): void => {
f(detail.button);
};
export const withSpan =
(f: (span: HTMLSpanElement) => void) =>
({ detail }: CustomEvent): void => {
f(detail.span);
};

View file

@ -7,6 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import type { DeckOptionsState } from "./lib"; import type { DeckOptionsState } from "./lib";
import type Dropdown from "bootstrap/js/dist/dropdown"; import type Dropdown from "bootstrap/js/dist/dropdown";
import { withButton } from "components/helpers";
import ButtonGroup from "components/ButtonGroup.svelte"; import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte"; import ButtonGroupItem from "components/ButtonGroupItem.svelte";
@ -65,7 +66,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
theme="primary" theme="primary"
on:click={() => save(false)} on:click={() => save(false)}
tooltip={shortcutLabel} tooltip={shortcutLabel}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
>{tr.deckConfigSaveButton()}</LabelButton >{tr.deckConfigSaveButton()}</LabelButton
> >
</WithShortcut> </WithShortcut>

View file

@ -3,18 +3,28 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import WithShortcut from "components/WithShortcut.svelte";
import Badge from "components/Badge.svelte"; import Badge from "components/Badge.svelte";
import { withSpan } from "components/helpers";
import { appendInParentheses } from "./helpers";
import { tagIcon, addTagIcon } from "./icons"; import { tagIcon, addTagIcon } from "./icons";
let theTagIcon = tagIcon; let theTagIcon = tagIcon;
const tooltip = "Add tag";
</script> </script>
<Badge <WithShortcut shortcut="Control+Shift+T" let:createShortcut let:shortcutLabel>
class="add-icon d-flex me-1" <Badge
on:click class="add-icon d-flex me-1"
on:mouseenter={() => (theTagIcon = addTagIcon)} tooltip={appendInParentheses(tooltip, shortcutLabel)}
on:mouseleave={() => (theTagIcon = tagIcon)}>{@html theTagIcon}</Badge on:click
> on:mouseenter={() => (theTagIcon = addTagIcon)}
on:mouseleave={() => (theTagIcon = tagIcon)}
on:mount={withSpan(createShortcut)}>{@html theTagIcon}</Badge
>
</WithShortcut>
<style lang="scss"> <style lang="scss">
:global(.add-icon > svg) { :global(.add-icon > svg) {

View file

@ -9,6 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import WithShortcut from "components/WithShortcut.svelte"; import WithShortcut from "components/WithShortcut.svelte";
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { withButton } from "components/helpers";
import { ellipseIcon } from "./icons"; import { ellipseIcon } from "./icons";
import { forEditorField } from "."; import { forEditorField } from ".";
import { wrapCurrent } from "./wrap"; import { wrapCurrent } from "./wrap";
@ -46,9 +47,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<OnlyEditable let:disabled> <OnlyEditable let:disabled>
<IconButton <IconButton
tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`} tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`}
{disabled} disabled={disabled}
on:click={onCloze} on:click={onCloze}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{@html ellipseIcon} {@html ellipseIcon}
</IconButton> </IconButton>

View file

@ -14,6 +14,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { bridgeCommand } from "lib/bridgecommand"; import { bridgeCommand } from "lib/bridgecommand";
import { withButton } from "components/helpers";
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons"; import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
import { appendInParentheses } from "./helpers"; import { appendInParentheses } from "./helpers";
@ -45,7 +46,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
)} )}
{disabled} {disabled}
on:click={forecolorWrap} on:click={forecolorWrap}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{@html textColorIcon} {@html textColorIcon}
{@html colorHelperIcon} {@html colorHelperIcon}
@ -71,7 +72,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
forecolorWrap = wrapWithForecolor(setColor(event)); forecolorWrap = wrapWithForecolor(setColor(event));
forecolorWrap(); forecolorWrap();
}} }}
on:mount={(event) => createShortcut(event.detail.input)} on:mount={withButton(createShortcut)}
/> />
</IconButton> </IconButton>
</WithShortcut> </WithShortcut>

View file

@ -8,6 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import WithState from "components/WithState.svelte"; import WithState from "components/WithState.svelte";
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { withButton } from "components/helpers";
import { appendInParentheses } from "./helpers"; import { appendInParentheses } from "./helpers";
export let key: string; export let key: string;
@ -48,7 +49,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
tooltip={appendInParentheses(tooltip, shortcutLabel)} tooltip={appendInParentheses(tooltip, shortcutLabel)}
{disabled} {disabled}
on:click={() => document.execCommand(key)} on:click={() => document.execCommand(key)}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
<slot /> <slot />
</IconButton> </IconButton>
@ -69,7 +70,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
document.execCommand(key); document.execCommand(key);
updateState(event); updateState(event);
}} }}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
<slot /> <slot />
</IconButton> </IconButton>

View file

@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="typescript"> <script lang="typescript">
import { bridgeCommand } from "lib/bridgecommand"; import { bridgeCommand } from "lib/bridgecommand";
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import { withButton } from "components/helpers";
import ButtonGroup from "components/ButtonGroup.svelte"; import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte"; import ButtonGroupItem from "components/ButtonGroupItem.svelte";
@ -29,7 +30,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<LabelButton <LabelButton
tooltip={`${tr.editingCustomizeCardTemplates()} (${shortcutLabel})`} tooltip={`${tr.editingCustomizeCardTemplates()} (${shortcutLabel})`}
on:click={() => bridgeCommand("cards")} on:click={() => bridgeCommand("cards")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingCards()}... {tr.editingCards()}...
</LabelButton> </LabelButton>

View file

@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="typescript"> <script lang="typescript">
import { bridgeCommand } from "lib/bridgecommand"; import { bridgeCommand } from "lib/bridgecommand";
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import { withButton } from "components/helpers";
import WithShortcut from "components/WithShortcut.svelte"; import WithShortcut from "components/WithShortcut.svelte";
import LabelButton from "components/LabelButton.svelte"; import LabelButton from "components/LabelButton.svelte";
@ -14,7 +15,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<LabelButton <LabelButton
tooltip={tr.browsingPreviewSelectedCard({ val: shortcutLabel })} tooltip={tr.browsingPreviewSelectedCard({ val: shortcutLabel })}
on:click={() => bridgeCommand("preview")} on:click={() => bridgeCommand("preview")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.actionsPreview()} {tr.actionsPreview()}
</LabelButton> </LabelButton>

View file

@ -32,7 +32,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</script> </script>
{#if active} {#if active}
<TagInputEdit bind:name on:focusout={() => (active = false)} on:update={updateTag} /> <TagInputEdit
bind:name
on:focusout={() => (active = false)}
on:update={updateTag}
/>
{:else} {:else}
<span <span
class="d-inline-flex align-items-center tag text-nowrap bg-secondary rounded ps-2 pe-1 me-1" class="d-inline-flex align-items-center tag text-nowrap bg-secondary rounded ps-2 pe-1 me-1"

View file

@ -31,11 +31,4 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/* } */ /* } */
</script> </script>
<TagInput <TagInput bind:name bind:input on:keydown={onKeydown} on:focusout on:update on:add />
bind:name
bind:input
on:keydown={onKeydown}
on:focusout
on:update
on:add
/>

View file

@ -19,6 +19,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ClozeButton from "./ClozeButton.svelte"; import ClozeButton from "./ClozeButton.svelte";
import { getCurrentField, appendInParentheses } from "./helpers"; import { getCurrentField, appendInParentheses } from "./helpers";
import { withButton } from "components/helpers";
import { wrapCurrent } from "./wrap"; import { wrapCurrent } from "./wrap";
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons"; import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
@ -52,7 +53,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
iconSize={70} iconSize={70}
{disabled} {disabled}
on:click={onAttachment} on:click={onAttachment}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{@html paperclipIcon} {@html paperclipIcon}
</IconButton> </IconButton>
@ -71,7 +72,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
iconSize={70} iconSize={70}
{disabled} {disabled}
on:click={onRecord} on:click={onRecord}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{@html micIcon} {@html micIcon}
</IconButton> </IconButton>
@ -90,7 +91,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<OnlyEditable let:disabled> <OnlyEditable let:disabled>
<IconButton <IconButton
{disabled} {disabled}
on:mount={(event) => createDropdown(event.detail.button)} on:mount={withButton(createDropdown)}
> >
{@html functionIcon} {@html functionIcon}
</IconButton> </IconButton>
@ -104,7 +105,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("\\(", "\\)")} on:click={() => wrapCurrent("\\(", "\\)")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingMathjaxInline()} {tr.editingMathjaxInline()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -118,7 +119,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("\\[", "\\]")} on:click={() => wrapCurrent("\\[", "\\]")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingMathjaxBlock()} {tr.editingMathjaxBlock()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -132,7 +133,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("\\(\\ce{", "}\\)")} on:click={() => wrapCurrent("\\(\\ce{", "}\\)")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingMathjaxChemistry()} {tr.editingMathjaxChemistry()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -146,7 +147,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("[latex]", "[/latex]")} on:click={() => wrapCurrent("[latex]", "[/latex]")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingLatex()} {tr.editingLatex()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -160,7 +161,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("[$]", "[/$]")} on:click={() => wrapCurrent("[$]", "[/$]")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingLatexEquation()} {tr.editingLatexEquation()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -174,7 +175,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
> >
<DropdownItem <DropdownItem
on:click={() => wrapCurrent("[$$]", "[/$$]")} on:click={() => wrapCurrent("[$$]", "[/$$]")}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{tr.editingLatexMathEnv()} {tr.editingLatexMathEnv()}
<span class="ps-1 float-end">{shortcutLabel}</span> <span class="ps-1 float-end">{shortcutLabel}</span>
@ -201,7 +202,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
active={inCodable} active={inCodable}
disabled={!fieldFocused} disabled={!fieldFocused}
on:click={onHtmlEdit} on:click={onHtmlEdit}
on:mount={(event) => createShortcut(event.detail.button)} on:mount={withButton(createShortcut)}
> >
{@html xmlIcon} {@html xmlIcon}
</IconButton> </IconButton>