chore(client/ts): port search_string

This commit is contained in:
Elian Doran 2025-02-24 13:50:08 +02:00
parent 8ab0084e10
commit 675a5e96e6
No known key found for this signature in database
3 changed files with 15 additions and 9 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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";
@ -35,6 +35,10 @@ const TPL = `
</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();