mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-03 14:19:58 +08:00
chore(client/ts): port search_string
This commit is contained in:
parent
8ab0084e10
commit
675a5e96e6
@ -369,6 +369,8 @@ class AppContext extends Component {
|
|||||||
layout?: Layout;
|
layout?: Layout;
|
||||||
noteTreeWidget?: NoteTreeWidget;
|
noteTreeWidget?: NoteTreeWidget;
|
||||||
|
|
||||||
|
lastSearchString?: string;
|
||||||
|
|
||||||
constructor(isMainWindow: boolean) {
|
constructor(isMainWindow: boolean) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import type { AttributeType } from "../../entities/fattribute.js";
|
|||||||
export default abstract class AbstractSearchOption extends Component {
|
export default abstract class AbstractSearchOption extends Component {
|
||||||
|
|
||||||
private attribute: FAttribute;
|
private attribute: FAttribute;
|
||||||
private note: FNote;
|
protected note: FNote;
|
||||||
|
|
||||||
constructor(attribute: FAttribute, note: FNote) {
|
constructor(attribute: FAttribute, note: FNote) {
|
||||||
super();
|
super();
|
||||||
|
@ -2,7 +2,7 @@ import AbstractSearchOption from "./abstract_search_option.js";
|
|||||||
import SpacedUpdate from "../../services/spaced_update.js";
|
import SpacedUpdate from "../../services/spaced_update.js";
|
||||||
import server from "../../services/server.js";
|
import server from "../../services/server.js";
|
||||||
import shortcutService from "../../services/shortcuts.js";
|
import shortcutService from "../../services/shortcuts.js";
|
||||||
import appContext from "../../components/app_context.js";
|
import appContext, { type EventData } from "../../components/app_context.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
import { Tooltip } from "bootstrap";
|
import { Tooltip } from "bootstrap";
|
||||||
|
|
||||||
@ -29,12 +29,16 @@ const TPL = `
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="bx bx-x icon-action search-option-del"></span>
|
<span class="bx bx-x icon-action search-option-del"></span>
|
||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
export default class SearchString extends AbstractSearchOption {
|
export default class SearchString extends AbstractSearchOption {
|
||||||
|
|
||||||
|
private $searchString!: JQuery<HTMLElement>;
|
||||||
|
private spacedUpdate!: SpacedUpdate;
|
||||||
|
|
||||||
static get optionName() {
|
static get optionName() {
|
||||||
return "searchString";
|
return "searchString";
|
||||||
}
|
}
|
||||||
@ -42,7 +46,7 @@ export default class SearchString extends AbstractSearchOption {
|
|||||||
return "label";
|
return "label";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(noteId) {
|
static async create(noteId: string) {
|
||||||
await AbstractSearchOption.setAttribute(noteId, "label", "searchString");
|
await AbstractSearchOption.setAttribute(noteId, "label", "searchString");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ export default class SearchString extends AbstractSearchOption {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.spacedUpdate = new SpacedUpdate(async () => {
|
this.spacedUpdate = new SpacedUpdate(async () => {
|
||||||
const searchString = this.$searchString.val();
|
const searchString = String(this.$searchString.val());
|
||||||
appContext.lastSearchString = searchString;
|
appContext.lastSearchString = searchString;
|
||||||
|
|
||||||
await this.setAttribute("label", "searchString", searchString);
|
await this.setAttribute("label", "searchString", searchString);
|
||||||
@ -73,13 +77,13 @@ export default class SearchString extends AbstractSearchOption {
|
|||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
this.$searchString.val(this.note.getLabelValue("searchString"));
|
this.$searchString.val(this.note.getLabelValue("searchString") ?? "");
|
||||||
|
|
||||||
return $option;
|
return $option;
|
||||||
}
|
}
|
||||||
|
|
||||||
showSearchErrorEvent({ error }) {
|
showSearchErrorEvent({ error }: EventData<"showSearchError">) {
|
||||||
let tooltip = new Tooltip(this.$searchString, {
|
let tooltip = new Tooltip(this.$searchString[0], {
|
||||||
trigger: "manual",
|
trigger: "manual",
|
||||||
title: `${t("search_string.error", { error })}`,
|
title: `${t("search_string.error", { error })}`,
|
||||||
placement: "bottom"
|
placement: "bottom"
|
||||||
@ -92,7 +96,7 @@ export default class SearchString extends AbstractSearchOption {
|
|||||||
|
|
||||||
focusOnSearchDefinitionEvent() {
|
focusOnSearchDefinitionEvent() {
|
||||||
this.$searchString
|
this.$searchString
|
||||||
.val(this.$searchString.val().trim() || appContext.lastSearchString)
|
.val(String(this.$searchString.val()).trim() ?? appContext.lastSearchString)
|
||||||
.focus()
|
.focus()
|
||||||
.select();
|
.select();
|
||||||
this.spacedUpdate.scheduleUpdate();
|
this.spacedUpdate.scheduleUpdate();
|
Loading…
x
Reference in New Issue
Block a user