mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51: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(); | ||||
|         var searchTerm = await this.handler.getInitialSearchTerm(); | ||||
|         searchTerm = searchTerm=="" ? window.getSelection().toString():searchTerm; | ||||
| 
 | ||||
|         const selectedText = window.getSelection().toString() || ""; | ||||
| 
 | ||||
|         this.$findBox.show(); | ||||
|         this.$input.focus(); | ||||
| @ -156,18 +156,21 @@ export default class FindWidget extends NoteContextAwareWidget { | ||||
|         const isAlreadyVisible = this.$findBox.is(":visible"); | ||||
| 
 | ||||
|         if (isAlreadyVisible) { | ||||
|             this.$input.val(searchTerm || ""); | ||||
|             if (searchTerm !== "") { | ||||
|                 this.$input.select(); | ||||
|             if (selectedText) { | ||||
|                 this.$input.val(selectedText); | ||||
|             } | ||||
| 
 | ||||
|             if (this.$input.val()) { | ||||
|                 await this.performFind(); | ||||
|             } | ||||
| 
 | ||||
|             this.$input.select(); | ||||
|         } else { | ||||
|             this.$totalFound.text(0); | ||||
|             this.$currentFound.text(0); | ||||
|             searchTerm = await this.handler.getInitialSearchTerm(); | ||||
|             this.$input.val(searchTerm || ""); | ||||
|             if (searchTerm !== "") { | ||||
|             this.$input.val(selectedText); | ||||
| 
 | ||||
|             if (selectedText) { | ||||
|                 this.$input.select(); | ||||
|                 await this.performFind(); | ||||
|             } | ||||
|  | ||||
| @ -16,23 +16,6 @@ export default class FindInCode { | ||||
|         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) { | ||||
|         let findResult = null; | ||||
|         let totalFound = 0; | ||||
|  | ||||
| @ -16,10 +16,6 @@ export default class FindInHtml { | ||||
|         this.$results = null; | ||||
|     } | ||||
| 
 | ||||
|     async getInitialSearchTerm() { | ||||
|         return ""; // FIXME
 | ||||
|     } | ||||
| 
 | ||||
|     async performFind(searchTerm, matchCase, wholeWord) { | ||||
|         await libraryLoader.requireLibrary(libraryLoader.MARKJS); | ||||
| 
 | ||||
|  | ||||
| @ -8,19 +8,6 @@ export default class FindInText { | ||||
|         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) { | ||||
|         // Do this even if the searchTerm is empty so the markers are cleared and
 | ||||
|         // the counters updated
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam