mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(in_app_help): reuse contextual help if possible
This commit is contained in:
		
							parent
							
								
									c649f473b4
								
							
						
					
					
						commit
						6953928f7a
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
import appContext from "../../components/app_context.js";
 | 
					import appContext from "../../components/app_context.js";
 | 
				
			||||||
import type { NoteType } from "../../entities/fnote.js";
 | 
					import type { NoteType } from "../../entities/fnote.js";
 | 
				
			||||||
import { t } from "../../services/i18n.js";
 | 
					import { t } from "../../services/i18n.js";
 | 
				
			||||||
 | 
					import type { ViewScope } from "../../services/link.js";
 | 
				
			||||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
 | 
					import NoteContextAwareWidget from "../note_context_aware_widget.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TPL = `
 | 
					const TPL = `
 | 
				
			||||||
@ -51,15 +52,24 @@ export default class ContextualHelpButton extends NoteContextAwareWidget {
 | 
				
			|||||||
        this.$widget = $(TPL);
 | 
					        this.$widget = $(TPL);
 | 
				
			||||||
        this.$widget.on("click", () => {
 | 
					        this.$widget.on("click", () => {
 | 
				
			||||||
            const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
 | 
					            const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
 | 
				
			||||||
 | 
					            const targetNote = `_help_${this.helpNoteIdToOpen}`;
 | 
				
			||||||
 | 
					            const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");
 | 
				
			||||||
 | 
					            const viewScope: ViewScope = {
 | 
				
			||||||
 | 
					                viewMode: "contextual-help",
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					            if (!helpSubcontext) {
 | 
				
			||||||
 | 
					                // The help is not already open, open a new split with it.
 | 
				
			||||||
                const { ntxId } = subContexts[subContexts.length - 1];
 | 
					                const { ntxId } = subContexts[subContexts.length - 1];
 | 
				
			||||||
                this.triggerCommand("openNewNoteSplit", {
 | 
					                this.triggerCommand("openNewNoteSplit", {
 | 
				
			||||||
                    ntxId,
 | 
					                    ntxId,
 | 
				
			||||||
                notePath: `_help_${this.helpNoteIdToOpen}`,
 | 
					                    notePath: targetNote,
 | 
				
			||||||
                    hoistedNoteId: "_help",
 | 
					                    hoistedNoteId: "_help",
 | 
				
			||||||
                viewScope: {
 | 
					                    viewScope
 | 
				
			||||||
                    viewMode: "contextual-help"
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                // There is already a help window open, make sure it opens on the right note.
 | 
				
			||||||
 | 
					                helpSubcontext.setNote(targetNote, { viewScope });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user