mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
small refactoring of search code
This commit is contained in:
parent
4bd298a55b
commit
2af37640d8
@ -16,7 +16,7 @@ async function convertMarkdownToHtml(text) {
|
||||
|
||||
const result = writer.render(parsed);
|
||||
|
||||
appContext.triggerEvent('executeInActiveEditor', {
|
||||
appContext.triggerCommand('executeInActiveEditor', {
|
||||
callback: textEditor => {
|
||||
const viewFragment = textEditor.data.processor.toView(result);
|
||||
const modelFragment = textEditor.data.toModel(viewFragment);
|
||||
|
@ -106,7 +106,7 @@ export default class ApperanceOptions {
|
||||
server.put('options/theme/' + newTheme);
|
||||
});
|
||||
|
||||
this.$zoomFactorSelect.on('change', () => { appContext.triggerEvent('setZoomFactorAndSave', {zoomFactor: this.$zoomFactorSelect.val()}); });
|
||||
this.$zoomFactorSelect.on('change', () => { appContext.triggerCommand('setZoomFactorAndSave', {zoomFactor: this.$zoomFactorSelect.val()}); });
|
||||
|
||||
this.$nativeTitleBarSelect.on('change', () => {
|
||||
const nativeTitleBarVisible = this.$nativeTitleBarSelect.val() === 'show' ? 'true' : 'false';
|
||||
|
@ -6,6 +6,7 @@ import treeCache from "./tree_cache.js";
|
||||
import server from "./server.js";
|
||||
import appContext from "./app_context.js";
|
||||
import Component from "../widgets/component.js";
|
||||
import toastService from "./toast.js";
|
||||
|
||||
export default class Entrypoints extends Component {
|
||||
constructor() {
|
||||
@ -142,4 +143,19 @@ export default class Entrypoints extends Component {
|
||||
forwardInNoteHistoryCommand() {
|
||||
window.history.forward();
|
||||
}
|
||||
|
||||
async searchForResultsCommand({searchText}) {
|
||||
const response = await server.get('search/' + encodeURIComponent(searchText));
|
||||
|
||||
if (!response.success) {
|
||||
toastService.showError("Search failed.", 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
this.triggerEvent('searchResults', {results: response.results});
|
||||
|
||||
// have at least some feedback which is good especially in situations
|
||||
// when the result list does not change with a query
|
||||
toastService.showMessage("Search finished successfully.");
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
await ws.waitForMaxKnownSyncId();
|
||||
|
||||
await appContext.tabManager.getActiveTabContext().setNote(notePath);
|
||||
appContext.triggerEvent('focusAndSelectTitle');
|
||||
appContext.triggerCommand('focusAndSelectTitle');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -276,7 +276,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @param {string} text - this must be clear text, HTML is not supported.
|
||||
* @method
|
||||
*/
|
||||
this.addTextToActiveTabEditor = text => appContext.triggerEvent('addTextToActiveEditor', {text});
|
||||
this.addTextToActiveTabEditor = text => appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
|
||||
/**
|
||||
* @method
|
||||
@ -290,7 +290,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
* @param callback - method receiving "textEditor" instance
|
||||
*/
|
||||
this.getActiveTabTextEditor = callback => appContext.triggerEvent('executeInActiveEditor', {callback});
|
||||
this.getActiveTabTextEditor = callback => appContext.triggerCommand('executeInActiveEditor', {callback});
|
||||
|
||||
/**
|
||||
* @method
|
||||
|
@ -40,7 +40,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
||||
this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate());
|
||||
|
||||
utils.bindElShortcut(this.$noteTitle, 'return', () => {
|
||||
this.triggerEvent('focusOnDetail', {tabId: this.tabContext.tabId});
|
||||
this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId});
|
||||
});
|
||||
|
||||
return this.$widget;
|
||||
|
@ -794,7 +794,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
editNoteTitleCommand({node}) {
|
||||
appContext.triggerEvent('focusOnTitle');
|
||||
appContext.triggerCommand('focusOnTitle');
|
||||
}
|
||||
|
||||
activateParentNoteCommand({node}) {
|
||||
|
@ -70,7 +70,7 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
|
||||
this.$saveSearchButton.on('click', () => this.saveSearch());
|
||||
|
||||
this.$closeSearchButton.on('click', () => this.triggerEvent('hideSearch'));
|
||||
this.$closeSearchButton.on('click', () => this.triggerCommand('hideSearch'));
|
||||
|
||||
return this.$widget;
|
||||
}
|
||||
@ -91,7 +91,7 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
this.triggerEvent('searchForResults', {
|
||||
this.triggerCommand('searchForResults', {
|
||||
searchText: this.$searchInput.val()
|
||||
});
|
||||
|
||||
@ -147,7 +147,7 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
|
||||
this.$searchBox.slideUp();
|
||||
|
||||
this.triggerEvent('hideSearchResults');
|
||||
this.triggerCommand('searchFlowEnded');
|
||||
}
|
||||
|
||||
toggleSearchEvent() {
|
||||
@ -159,7 +159,7 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
}
|
||||
}
|
||||
|
||||
searchNotesCommand() {
|
||||
searchNotesEvent() {
|
||||
this.toggleSearchEvent();
|
||||
}
|
||||
|
||||
|
@ -39,20 +39,13 @@ export default class SearchResultsWidget extends BasicWidget {
|
||||
return this.$widget;
|
||||
}
|
||||
|
||||
async searchForResultsEvent({searchText}) {
|
||||
searchResultsEvent({results}) {
|
||||
this.toggle(true);
|
||||
|
||||
const response = await server.get('search/' + encodeURIComponent(searchText));
|
||||
|
||||
if (!response.success) {
|
||||
toastService.showError("Search failed.", 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
this.$searchResultsInner.empty();
|
||||
this.$searchResults.show();
|
||||
|
||||
for (const result of response.results) {
|
||||
for (const result of results) {
|
||||
const link = $('<a>', {
|
||||
href: 'javascript:',
|
||||
text: result.title
|
||||
@ -62,13 +55,9 @@ export default class SearchResultsWidget extends BasicWidget {
|
||||
|
||||
this.$searchResultsInner.append($result);
|
||||
}
|
||||
|
||||
// have at least some feedback which is good especially in situations
|
||||
// when the result list does not change with a query
|
||||
toastService.showMessage("Search finished successfully.");
|
||||
}
|
||||
|
||||
hideSearchResultsEvent() {
|
||||
searchFlowEndedEvent() {
|
||||
this.$searchResults.hide();
|
||||
}
|
||||
}
|
@ -71,8 +71,8 @@ export default class StandardTopWidget extends BasicWidget {
|
||||
|
||||
this.$widget.prepend(historyNavigationWidget.render());
|
||||
|
||||
this.$widget.find(".jump-to-note-dialog-button").on('click', () => this.triggerEvent('jumpToNote'));
|
||||
this.$widget.find(".recent-changes-button").on('click', () => this.triggerEvent('showRecentChanges'));
|
||||
this.$widget.find(".jump-to-note-dialog-button").on('click', () => this.triggerCommand('jumpToNote'));
|
||||
this.$widget.find(".recent-changes-button").on('click', () => this.triggerCommand('showRecentChanges'));
|
||||
|
||||
this.$widget.find(".enter-protected-session-button").on('click', protectedSessionService.enterProtectedSession);
|
||||
this.$widget.find(".leave-protected-session-button").on('click', protectedSessionService.leaveProtectedSession);
|
||||
|
Loading…
x
Reference in New Issue
Block a user