import AbstractSearchOption from "./abstract_search_option.js"; import utils from "../../services/utils.js"; import SpacedUpdate from "../../services/spaced_update.js"; import server from "../../services/server.js"; const TPL = ` Search string: `; export default class SearchString extends AbstractSearchOption { static get optionName() { return "searchString" }; static get attributeType() { return "label" }; static async create(noteId) { await AbstractSearchOption.setAttribute(noteId, 'label', 'searchString'); } doRender() { const $option = $(TPL); this.$searchString = $option.find('.search-string'); this.$searchString.on('input', () => this.spacedUpdate.scheduleUpdate()); utils.bindElShortcut(this.$searchString, 'return', async () => { await this.spacedUpdate.updateNowIfNecessary(); this.triggerCommand('refreshResults'); }); this.spacedUpdate = new SpacedUpdate(async () => { const searchString = this.$searchString.val(); await this.setAttribute('label', 'searchString', searchString); if (this.note.title.startsWith('Search: ')) { await server.put(`notes/${this.note.noteId}/change-title`, { title: 'Search: ' + (searchString.length < 30 ? searchString : `${searchString.substr(0, 30)}…`) }); } }, 1000); this.$searchString.val(this.note.getLabelValue('searchString')); return $option; } focusOnSearchDefinitionEvent() { this.$searchString.focus(); } }