mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	refactoring
This commit is contained in:
		| @@ -64,7 +64,7 @@ export default class DialogCommandExecutor extends Component { | |||||||
|  |  | ||||||
|         const tabContext = await appContext.tabManager.openTabWithNote(sqlConsoleNote.noteId, true); |         const tabContext = await appContext.tabManager.openTabWithNote(sqlConsoleNote.noteId, true); | ||||||
|  |  | ||||||
|         appContext.triggerCommand('focusOnDetail', {tabId: tabContext.tabId}); |         appContext.triggerEvent('focusOnDetail', {tabId: tabContext.tabId}); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async searchNotesCommand({searchString, ancestorNoteId}) { |     async searchNotesCommand({searchString, ancestorNoteId}) { | ||||||
|   | |||||||
| @@ -56,10 +56,10 @@ async function createNote(parentNoteId, options = {}) { | |||||||
|         await activeTabContext.setNote(note.noteId); |         await activeTabContext.setNote(note.noteId); | ||||||
|  |  | ||||||
|         if (options.focus === 'title') { |         if (options.focus === 'title') { | ||||||
|             appContext.triggerCommand('focusAndSelectTitle'); |             appContext.triggerEvent('focusAndSelectTitle'); | ||||||
|         } |         } | ||||||
|         else if (options.focus === 'content') { |         else if (options.focus === 'content') { | ||||||
|             appContext.triggerCommand('focusOnDetail', {tabId: activeTabContext.tabId}); |             appContext.triggerEvent('focusOnDetail', {tabId: activeTabContext.tabId}); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,15 +26,60 @@ class TabContext extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async setNote(inputNotePath, triggerSwitchEvent = true) { |     async setNote(inputNotePath, triggerSwitchEvent = true) { | ||||||
|  |         const resolvedNotePath = await this.getResolvedNotePath(inputNotePath); | ||||||
|  |  | ||||||
|  |         if (!resolvedNotePath) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         await this.triggerEvent('beforeNoteSwitch', {tabContext: this}); | ||||||
|  |  | ||||||
|  |         utils.closeActiveDialog(); | ||||||
|  |  | ||||||
|  |         this.notePath = resolvedNotePath; | ||||||
|  |         this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath); | ||||||
|  |  | ||||||
|  |         this.textPreviewDisabled = false; | ||||||
|  |         this.codePreviewDisabled = false; | ||||||
|  |  | ||||||
|  |         this.saveToRecentNotes(resolvedNotePath); | ||||||
|  |  | ||||||
|  |         protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); | ||||||
|  |  | ||||||
|  |         if (triggerSwitchEvent) { | ||||||
|  |             await this.triggerEvent('tabNoteSwitched', { | ||||||
|  |                 tabContext: this, | ||||||
|  |                 notePath: this.notePath | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (utils.isDesktop()) { | ||||||
|  |             // close dangling autocompletes after closing the tab | ||||||
|  |             $(".aa-input").autocomplete("close"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     saveToRecentNotes(resolvedNotePath) { | ||||||
|  |         setTimeout(async () => { | ||||||
|  |             // we include the note into recent list only if the user stayed on the note at least 5 seconds | ||||||
|  |             if (resolvedNotePath && resolvedNotePath === this.notePath) { | ||||||
|  |                 await server.post('recent-notes', { | ||||||
|  |                     noteId: this.note.noteId, | ||||||
|  |                     notePath: this.notePath | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |         }, 5000); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async getResolvedNotePath(inputNotePath) { | ||||||
|         const noteId = treeService.getNoteIdFromNotePath(inputNotePath); |         const noteId = treeService.getNoteIdFromNotePath(inputNotePath); | ||||||
|         let resolvedNotePath; |  | ||||||
|  |  | ||||||
|         if ((await treeCache.getNote(noteId)).isDeleted) { |         if ((await treeCache.getNote(noteId)).isDeleted) { | ||||||
|             // no point in trying to resolve canonical notePath |             // no point in trying to resolve canonical notePath | ||||||
|             resolvedNotePath = inputNotePath; |             return inputNotePath; | ||||||
|         } |         } | ||||||
|         else { |  | ||||||
|             resolvedNotePath = await treeService.resolveNotePath(inputNotePath); |         const resolvedNotePath = await treeService.resolveNotePath(inputNotePath); | ||||||
|  |  | ||||||
|         if (!resolvedNotePath) { |         if (!resolvedNotePath) { | ||||||
|             logError(`Cannot resolve note path ${inputNotePath}`); |             logError(`Cannot resolve note path ${inputNotePath}`); | ||||||
| @@ -51,41 +96,8 @@ class TabContext extends Component { | |||||||
|  |  | ||||||
|         // if user choise to unhoist, cache was reloaded, but might not contain this note (since it's on unexpanded path) |         // if user choise to unhoist, cache was reloaded, but might not contain this note (since it's on unexpanded path) | ||||||
|         await treeCache.getNote(noteId); |         await treeCache.getNote(noteId); | ||||||
|         } |  | ||||||
|  |  | ||||||
|         await this.triggerEvent('beforeNoteSwitch', {tabContext: this}); |         return resolvedNotePath; | ||||||
|  |  | ||||||
|         utils.closeActiveDialog(); |  | ||||||
|  |  | ||||||
|         this.notePath = resolvedNotePath; |  | ||||||
|         this.noteId = noteId; |  | ||||||
|  |  | ||||||
|         this.textPreviewDisabled = false; |  | ||||||
|         this.codePreviewDisabled = false; |  | ||||||
|  |  | ||||||
|         setTimeout(async () => { |  | ||||||
|             // we include the note into recent list only if the user stayed on the note at least 5 seconds |  | ||||||
|             if (resolvedNotePath && resolvedNotePath === this.notePath) { |  | ||||||
|                 await server.post('recent-notes', { |  | ||||||
|                     noteId: this.note.noteId, |  | ||||||
|                     notePath: this.notePath |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|         }, 5000); |  | ||||||
|  |  | ||||||
|         protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); |  | ||||||
|  |  | ||||||
|         if (triggerSwitchEvent) { |  | ||||||
|             await this.triggerEvent('tabNoteSwitched', { |  | ||||||
|                 tabContext: this, |  | ||||||
|                 notePath: this.notePath |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (utils.isDesktop()) { |  | ||||||
|             // close dangling autocompletes after closing the tab |  | ||||||
|             $(".aa-input").autocomplete("close"); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @property {NoteShort} */ |     /** @property {NoteShort} */ | ||||||
|   | |||||||
| @@ -485,7 +485,7 @@ export default class AttributeEditorWidget extends TabAwareWidget { | |||||||
|                 }); |                 }); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId}); |                 this.triggerEvent('focusOnDetail', {tabId: this.tabContext.tabId}); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -249,7 +249,6 @@ export default class NoteDetailWidget extends TabAwareWidget { | |||||||
|             loadCSS: [ |             loadCSS: [ | ||||||
|                 "libraries/codemirror/codemirror.css", |                 "libraries/codemirror/codemirror.css", | ||||||
|                 "libraries/ckeditor/ckeditor-content.css", |                 "libraries/ckeditor/ckeditor-content.css", | ||||||
|                 "libraries/ckeditor/ckeditor-content.css", |  | ||||||
|                 "libraries/bootstrap/css/bootstrap.min.css", |                 "libraries/bootstrap/css/bootstrap.min.css", | ||||||
|                 "libraries/katex/katex.min.css", |                 "libraries/katex/katex.min.css", | ||||||
|                 "stylesheets/print.css", |                 "stylesheets/print.css", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user