mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
This commit is contained in:
parent
20f49699ad
commit
9729b72a9e
1 changed files with 20 additions and 14 deletions
|
|
@ -419,11 +419,15 @@ export class Background {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeTag(protyle: IProtyle) {
|
private removeTag(protyle: IProtyle, cb?: () => void) {
|
||||||
const tags = this.getTags();
|
const tags = this.getTags();
|
||||||
fetchPost("/api/attr/setBlockAttrs", {
|
fetchPost("/api/attr/setBlockAttrs", {
|
||||||
id: protyle.block.rootID,
|
id: protyle.block.rootID,
|
||||||
attrs: {"tags": tags.toString()}
|
attrs: {"tags": tags.toString()}
|
||||||
|
}, () => {
|
||||||
|
if (cb) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (tags.length === 0) {
|
if (tags.length === 0) {
|
||||||
delete this.ial.tags;
|
delete this.ial.tags;
|
||||||
|
|
@ -540,13 +544,10 @@ export class Background {
|
||||||
upDownHint(listElement, event);
|
upDownHint(listElement, event);
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
const currentElement = listElement.querySelector(".b3-list-item--focus");
|
const currentElement = listElement.querySelector(".b3-list-item--focus");
|
||||||
if (currentElement) {
|
this.addTags(currentElement ? currentElement.textContent.trim() : inputElement.value.trim(), protyle, () => {
|
||||||
this.addTags(currentElement.textContent.trim(), protyle);
|
|
||||||
} else {
|
|
||||||
this.addTags(inputElement.value.trim(), protyle);
|
|
||||||
}
|
|
||||||
inputElement.value = "";
|
inputElement.value = "";
|
||||||
inputElement.dispatchEvent(new CustomEvent("input"));
|
inputElement.dispatchEvent(new CustomEvent("input"));
|
||||||
|
});
|
||||||
} else if (event.key === "Escape") {
|
} else if (event.key === "Escape") {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
}
|
}
|
||||||
|
|
@ -554,7 +555,7 @@ export class Background {
|
||||||
inputElement.addEventListener("input", (event) => {
|
inputElement.addEventListener("input", (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
fetchPost("/api/search/searchTag", {
|
fetchPost("/api/search/searchTag", {
|
||||||
k: inputElement.value,
|
k: inputElement.value.trim(),
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
let searchHTML = "";
|
let searchHTML = "";
|
||||||
let hasKey = false;
|
let hasKey = false;
|
||||||
|
|
@ -569,7 +570,7 @@ export class Background {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!hasKey && response.data.k) {
|
if (!hasKey && response.data.k) {
|
||||||
searchHTML = `<div class="b3-list-item b3-list-item--narrow${searchHTML ? "" : " b3-list-item--focus"}"><div class="fn__flex-1">${window.siyuan.languages.new} <mark>${escapeHtml(response.data.k)}</mark></div></div>` + searchHTML;
|
searchHTML = `<div data-type="new" class="b3-list-item b3-list-item--narrow${searchHTML ? "" : " b3-list-item--focus"}"><div class="fn__flex-1">${window.siyuan.languages.new} <mark>${escapeHtml(response.data.k)}</mark></div></div>` + searchHTML;
|
||||||
}
|
}
|
||||||
listElement.innerHTML = searchHTML;
|
listElement.innerHTML = searchHTML;
|
||||||
});
|
});
|
||||||
|
|
@ -580,9 +581,12 @@ export class Background {
|
||||||
if (!listItemElement) {
|
if (!listItemElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.addTags(listItemElement.textContent.trim(), protyle);
|
this.addTags(listItemElement.dataset.type === "new" ? listItemElement.querySelector("mark").textContent.trim() : listItemElement.textContent.trim(),
|
||||||
|
protyle, () => {
|
||||||
|
inputElement.value = "";
|
||||||
inputElement.dispatchEvent(new CustomEvent("input"));
|
inputElement.dispatchEvent(new CustomEvent("input"));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const itemsElement = menu.element.querySelector(".b3-menu__items");
|
const itemsElement = menu.element.querySelector(".b3-menu__items");
|
||||||
|
|
@ -609,16 +613,18 @@ export class Background {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
private addTags(tag: string, protyle: IProtyle) {
|
private addTags(tag: string, protyle: IProtyle, cb: () => void) {
|
||||||
const tags = this.getTags(tag);
|
const tags = this.getTags(tag);
|
||||||
if (tags.includes(tag)) {
|
if (tags.includes(tag)) {
|
||||||
this.removeTag(protyle);
|
this.removeTag(protyle, cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
fetchPost("/api/attr/setBlockAttrs", {
|
fetchPost("/api/attr/setBlockAttrs", {
|
||||||
id: protyle.block.rootID,
|
id: protyle.block.rootID,
|
||||||
attrs: {"tags": tags.toString()}
|
attrs: {"tags": tags.toString()}
|
||||||
|
}, () => {
|
||||||
|
cb();
|
||||||
});
|
});
|
||||||
this.ial.tags = tags.toString();
|
this.ial.tags = tags.toString();
|
||||||
this.render(this.ial, protyle.block.rootID);
|
this.render(this.ial, protyle.block.rootID);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue