mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	cleanup of find in text implementation
This commit is contained in:
		
							parent
							
								
									1089e84f56
								
							
						
					
					
						commit
						074820dae5
					
				@ -147,8 +147,8 @@ export default class FindWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.handler = await this.getHandler();
 | 
					        this.handler = await this.getHandler();
 | 
				
			||||||
        var searchTerm = await this.handler.getInitialSearchTerm();
 | 
					
 | 
				
			||||||
        searchTerm = searchTerm=="" ? window.getSelection().toString():searchTerm;
 | 
					        const selectedText = window.getSelection().toString() || "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.$findBox.show();
 | 
					        this.$findBox.show();
 | 
				
			||||||
        this.$input.focus();
 | 
					        this.$input.focus();
 | 
				
			||||||
@ -156,18 +156,21 @@ export default class FindWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        const isAlreadyVisible = this.$findBox.is(":visible");
 | 
					        const isAlreadyVisible = this.$findBox.is(":visible");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isAlreadyVisible) {
 | 
					        if (isAlreadyVisible) {
 | 
				
			||||||
            this.$input.val(searchTerm || "");
 | 
					            if (selectedText) {
 | 
				
			||||||
            if (searchTerm !== "") {
 | 
					                this.$input.val(selectedText);
 | 
				
			||||||
                this.$input.select();
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (this.$input.val()) {
 | 
				
			||||||
                await this.performFind();
 | 
					                await this.performFind();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.$input.select();
 | 
					            this.$input.select();
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.$totalFound.text(0);
 | 
					            this.$totalFound.text(0);
 | 
				
			||||||
            this.$currentFound.text(0);
 | 
					            this.$currentFound.text(0);
 | 
				
			||||||
            searchTerm = await this.handler.getInitialSearchTerm();
 | 
					            this.$input.val(selectedText);
 | 
				
			||||||
            this.$input.val(searchTerm || "");
 | 
					
 | 
				
			||||||
            if (searchTerm !== "") {
 | 
					            if (selectedText) {
 | 
				
			||||||
                this.$input.select();
 | 
					                this.$input.select();
 | 
				
			||||||
                await this.performFind();
 | 
					                await this.performFind();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -16,23 +16,6 @@ export default class FindInCode {
 | 
				
			|||||||
        return this.parent.noteContext.getCodeEditor();
 | 
					        return this.parent.noteContext.getCodeEditor();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async getInitialSearchTerm() {
 | 
					 | 
				
			||||||
        const codeEditor = await this.getCodeEditor();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // highlightSelectionMatches is the overlay that highlights
 | 
					 | 
				
			||||||
        // the words under the cursor. This occludes the search
 | 
					 | 
				
			||||||
        // markers style, save it, disable it. Will be restored when
 | 
					 | 
				
			||||||
        // the focus is back into the note
 | 
					 | 
				
			||||||
        this.oldHighlightSelectionMatches = codeEditor.getOption("highlightSelectionMatches");
 | 
					 | 
				
			||||||
        codeEditor.setOption("highlightSelectionMatches", false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Fill in the findbox with the current selection if any
 | 
					 | 
				
			||||||
        const selectedText = codeEditor.getSelection()
 | 
					 | 
				
			||||||
        if (selectedText !== "") {
 | 
					 | 
				
			||||||
            return selectedText;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async performFind(searchTerm, matchCase, wholeWord) {
 | 
					    async performFind(searchTerm, matchCase, wholeWord) {
 | 
				
			||||||
        let findResult = null;
 | 
					        let findResult = null;
 | 
				
			||||||
        let totalFound = 0;
 | 
					        let totalFound = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -16,10 +16,6 @@ export default class FindInHtml {
 | 
				
			|||||||
        this.$results = null;
 | 
					        this.$results = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async getInitialSearchTerm() {
 | 
					 | 
				
			||||||
        return ""; // FIXME
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async performFind(searchTerm, matchCase, wholeWord) {
 | 
					    async performFind(searchTerm, matchCase, wholeWord) {
 | 
				
			||||||
        await libraryLoader.requireLibrary(libraryLoader.MARKJS);
 | 
					        await libraryLoader.requireLibrary(libraryLoader.MARKJS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,19 +8,6 @@ export default class FindInText {
 | 
				
			|||||||
        return this.parent.noteContext.getTextEditor();
 | 
					        return this.parent.noteContext.getTextEditor();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async getInitialSearchTerm() {
 | 
					 | 
				
			||||||
        const textEditor = await this.getTextEditor();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const selection = textEditor.model.document.selection;
 | 
					 | 
				
			||||||
        const range = selection.getFirstRange();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // FIXME
 | 
					 | 
				
			||||||
        for (const item of range.getItems()) {
 | 
					 | 
				
			||||||
            // Fill in the findbox with the current selection if any
 | 
					 | 
				
			||||||
            return item.data;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async performFind(searchTerm, matchCase, wholeWord) {
 | 
					    async performFind(searchTerm, matchCase, wholeWord) {
 | 
				
			||||||
        // Do this even if the searchTerm is empty so the markers are cleared and
 | 
					        // Do this even if the searchTerm is empty so the markers are cleared and
 | 
				
			||||||
        // the counters updated
 | 
					        // the counters updated
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user