mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Set tags from Python
This commit is contained in:
parent
a034c93eb7
commit
375a96e263
3 changed files with 22 additions and 14 deletions
|
@ -481,12 +481,13 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
|
|||
text_color = self.mw.pm.profile.get("lastTextColor", "#00f")
|
||||
highlight_color = self.mw.pm.profile.get("lastHighlightColor", "#00f")
|
||||
|
||||
js = "setFields(%s); setFonts(%s); focusField(%s); setNoteId(%s); setColorButtons(%s);" % (
|
||||
js = "setFields(%s); setFonts(%s); focusField(%s); setNoteId(%s); setColorButtons(%s); setTags(%s); " % (
|
||||
json.dumps(data),
|
||||
json.dumps(self.fonts()),
|
||||
json.dumps(focusTo),
|
||||
json.dumps(self.note.id),
|
||||
json.dumps([text_color, highlight_color]),
|
||||
json.dumps(self.mw.col.tags.canonify(self.note.tags)),
|
||||
)
|
||||
|
||||
if self.addMode:
|
||||
|
|
|
@ -14,25 +14,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import type { Tag as TagType } from "./tags";
|
||||
import { attachId, getName } from "./tags";
|
||||
|
||||
export let initialNames = ["en::foobar", "test", "def"];
|
||||
export let suggestions = ["en::idioms", "anki::functionality", "math"];
|
||||
|
||||
export let size = isApplePlatform() ? 1.6 : 2.0;
|
||||
|
||||
let input: HTMLInputElement;
|
||||
let tags = initialNames.map(attachId);
|
||||
export let suggestions = ["en::idioms", "anki::functionality", "math"];
|
||||
|
||||
function isFirst(index: number): boolean {
|
||||
return index === 0;
|
||||
}
|
||||
export let tags: TagType[] = [];
|
||||
|
||||
function isLast(index: number): boolean {
|
||||
return index === tags.length - 1;
|
||||
export function resetTags(names: string[]) {
|
||||
tags = names.map(attachId);
|
||||
}
|
||||
|
||||
let active: number | null = null;
|
||||
let activeAfterBlur: number | null = null;
|
||||
let activeName = "";
|
||||
let activeInput: HTMLInputElement;
|
||||
|
||||
function onAutocomplete({ detail }) {
|
||||
const activeTag = tags[active!];
|
||||
|
@ -114,7 +109,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
// splitOff tag was rejected
|
||||
return;
|
||||
}
|
||||
input.setSelectionRange(0, 0);
|
||||
activeInput.setSelectionRange(0, 0);
|
||||
}
|
||||
|
||||
function insertTag(index: number): void {
|
||||
|
@ -136,6 +131,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
return deleted;
|
||||
}
|
||||
|
||||
function isFirst(index: number): boolean {
|
||||
return index === 0;
|
||||
}
|
||||
|
||||
function isLast(index: number): boolean {
|
||||
return index === tags.length - 1;
|
||||
}
|
||||
|
||||
function joinWithPreviousTag(index: number): void {
|
||||
if (isFirst(index)) {
|
||||
return;
|
||||
|
@ -182,7 +185,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
active = null;
|
||||
|
||||
await tick();
|
||||
input.setSelectionRange(0, 0);
|
||||
activeInput.setSelectionRange(0, 0);
|
||||
}
|
||||
|
||||
function deleteTagIfNotUnique(tag: TagType, index: number): void {
|
||||
|
@ -220,7 +223,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<TagInput
|
||||
id={tag.id}
|
||||
bind:name={activeName}
|
||||
bind:input
|
||||
bind:input={activeInput}
|
||||
on:focus={() => (activeName = tag.name)}
|
||||
on:keydown={updateAutocomplete}
|
||||
on:input={() => updateWithTagName(tag)}
|
||||
|
|
|
@ -195,6 +195,10 @@ export function setFormat(cmd: string, arg?: string, nosave = false): void {
|
|||
}
|
||||
}
|
||||
|
||||
export function setTags(tags: string[]): void {
|
||||
$tagEditor.then((tagEditor: TagEditor): void => tagEditor.resetTags(tags));
|
||||
}
|
||||
|
||||
export const i18n = setupI18n({
|
||||
modules: [
|
||||
ModuleName.EDITING,
|
||||
|
|
Loading…
Reference in a new issue