mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	fix(code): pressing tab while multiple lines are selected would replace with tab
This commit is contained in:
		
							parent
							
								
									03de472a57
								
							
						
					
					
						commit
						9e3909a5f7
					
				| @ -24,6 +24,23 @@ const smartIndentWithTab: KeyBinding[] = [ | ||||
| 
 | ||||
|             // Step 1: Handle non-empty selections → replace with tab
 | ||||
|             if (selection.ranges.some(range => !range.empty)) { | ||||
|                 // If multiple lines are selected, insert a tab character at the start of each line
 | ||||
|                 // and move the cursor to the position after the tab character.
 | ||||
|                 const linesCovered = new Set<number>(); | ||||
|                 for (const range of selection.ranges) { | ||||
|                     const startLine = state.doc.lineAt(range.from); | ||||
|                     const endLine = state.doc.lineAt(range.to); | ||||
| 
 | ||||
|                     for (let lineNumber = startLine.number; lineNumber <= endLine.number; lineNumber++) { | ||||
|                         linesCovered.add(lineNumber); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (linesCovered.size > 1) { | ||||
|                     // Multiple lines are selected, indent each line.
 | ||||
|                     return indentMore({ state, dispatch }); | ||||
|                 } else { | ||||
|                     // Single line selection, replace with tab.
 | ||||
|                     for (let range of selection.ranges) { | ||||
|                         changes.push({ from: range.from, to: range.to, insert: "\t" }); | ||||
|                         newSelections.push(EditorSelection.cursor(range.from + 1)); | ||||
| @ -37,6 +54,8 @@ const smartIndentWithTab: KeyBinding[] = [ | ||||
|                             userEvent: "input" | ||||
|                         }) | ||||
|                     ); | ||||
|                 } | ||||
| 
 | ||||
|                 return true; | ||||
|             } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran