mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	chore(code/find): scroll to nearest result
This commit is contained in:
		
							parent
							
								
									c4863dec50
								
							
						
					
					
						commit
						e08011b3d6
					
				@ -57,9 +57,22 @@ export function createSearchHighlighter(view: EditorView, searchTerm: string, ma
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const pos = this.parsedMatches[matchIndex];
 | 
					            this.scrollTo(this.parsedMatches[matchIndex]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        scrollToMatchNearestSelection() {
 | 
				
			||||||
 | 
					            const cursorPos = this.view.state.selection.main.head;
 | 
				
			||||||
 | 
					            for (const match of this.parsedMatches) {
 | 
				
			||||||
 | 
					                if (match.from >= cursorPos) {
 | 
				
			||||||
 | 
					                    this.scrollTo(match);
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private scrollTo(match: Match) {
 | 
				
			||||||
            this.view.dispatch({
 | 
					            this.view.dispatch({
 | 
				
			||||||
                effects: EditorView.scrollIntoView(pos.from, { y: "center" }),
 | 
					                effects: EditorView.scrollIntoView(match.from, { y: "center" }),
 | 
				
			||||||
                scrollIntoView: true
 | 
					                scrollIntoView: true
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -181,7 +181,7 @@ export default class CodeMirror extends EditorView {
 | 
				
			|||||||
        await new Promise(requestAnimationFrame);
 | 
					        await new Promise(requestAnimationFrame);
 | 
				
			||||||
        const instance = this.plugin(plugin);
 | 
					        const instance = this.plugin(plugin);
 | 
				
			||||||
        if (instance) {
 | 
					        if (instance) {
 | 
				
			||||||
            instance.scrollToMatch(0);
 | 
					            instance.scrollToMatchNearestSelection();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user