0026506543
- prettier's formatting has changed, so files needed to be reformatted - dart is spitting out deprecation warnings like: 254 │ 2: $spacer / 2, │ ^^^^^^^^^^^ ╵ bazel-out/darwin-fastbuild/bin/ts/sass/bootstrap/_variables.scss 254:6 @import ts/sass/button_mixins.scss 2:9 @use ts/components/ColorPicker.svelte 2:5 root stylesheet DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0. Recommendation: math.div($grid-gutter-width, 2)
53 lines
1.5 KiB
Svelte
53 lines
1.5 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="typescript">
|
|
import * as tr from "lib/i18n";
|
|
|
|
import IconButton from "components/IconButton.svelte";
|
|
import WithShortcut from "components/WithShortcut.svelte";
|
|
|
|
import { bracketsIcon } from "./icons";
|
|
import { forEditorField } from ".";
|
|
import { wrap } from "./wrap";
|
|
|
|
const clozePattern = /\{\{c(\d+)::/gu;
|
|
function getCurrentHighestCloze(increment: boolean): number {
|
|
let highest = 0;
|
|
|
|
forEditorField([], (field) => {
|
|
const fieldHTML = field.editingArea.editable.fieldHTML;
|
|
const matches: number[] = [];
|
|
let match: RegExpMatchArray | null = null;
|
|
|
|
while ((match = clozePattern.exec(fieldHTML))) {
|
|
matches.push(Number(match[1]));
|
|
}
|
|
|
|
highest = Math.max(highest, ...matches);
|
|
});
|
|
|
|
if (increment) {
|
|
highest++;
|
|
}
|
|
|
|
return Math.max(1, highest);
|
|
}
|
|
|
|
function onCloze(event: KeyboardEvent | MouseEvent): void {
|
|
const highestCloze = getCurrentHighestCloze(!event.getModifierState("Alt"));
|
|
wrap(`{{c${highestCloze}::`, "}}");
|
|
}
|
|
</script>
|
|
|
|
<WithShortcut shortcut={"Control+Alt?+Shift+C"} let:createShortcut let:shortcutLabel>
|
|
<IconButton
|
|
tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`}
|
|
on:click={onCloze}
|
|
on:mount={createShortcut}
|
|
>
|
|
{@html bracketsIcon}
|
|
</IconButton>
|
|
</WithShortcut>
|