mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Fix colon insertion behavior
This commit is contained in:
parent
85691fada2
commit
ef539bcb37
1 changed files with 17 additions and 3 deletions
|
@ -4,7 +4,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { onMount, createEventDispatcher, tick } from "svelte";
|
import { onMount, createEventDispatcher, tick } from "svelte";
|
||||||
import { normalizeTagname, delimChar, replaceWithColon } from "./tags";
|
import {
|
||||||
|
normalizeTagname,
|
||||||
|
delimChar,
|
||||||
|
replaceWithDelimChar,
|
||||||
|
replaceWithColon,
|
||||||
|
} from "./tags";
|
||||||
|
|
||||||
export let id: string | undefined = undefined;
|
export let id: string | undefined = undefined;
|
||||||
let className: string = "";
|
let className: string = "";
|
||||||
|
@ -110,6 +115,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
const positionEnd = input.selectionEnd!;
|
const positionEnd = input.selectionEnd!;
|
||||||
|
|
||||||
const before = name.slice(0, positionStart);
|
const before = name.slice(0, positionStart);
|
||||||
|
const after = name.slice(positionEnd, name.length);
|
||||||
|
|
||||||
if (before.endsWith(delimChar)) {
|
if (before.endsWith(delimChar)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -121,11 +127,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
positionEnd,
|
positionEnd,
|
||||||
name.length
|
name.length
|
||||||
)}`;
|
)}`;
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
setPosition(positionStart);
|
||||||
|
return;
|
||||||
|
} else if (after.startsWith(":")) {
|
||||||
|
event.preventDefault();
|
||||||
|
name = `${before}${delimChar}${name.slice(positionEnd + 1, name.length)}`;
|
||||||
} else if (single) {
|
} else if (single) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
name = `${before}${delimChar}${name.slice(positionEnd, name.length)}`;
|
name = `${before}${delimChar}${after}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
|
@ -195,7 +208,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
const splitted = pasted
|
const splitted = pasted
|
||||||
.split(/\s+/)
|
.split(/\s+/)
|
||||||
.map(normalizeTagname)
|
.map(normalizeTagname)
|
||||||
.filter((name: string) => name.length > 0);
|
.filter((name: string) => name.length > 0)
|
||||||
|
.map(replaceWithDelimChar);
|
||||||
|
|
||||||
if (splitted.length === 0) {
|
if (splitted.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue