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