mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	This commit is contained in:
		
							parent
							
								
									7f1eb99127
								
							
						
					
					
						commit
						8b7f16d49b
					
				
							
								
								
									
										1
									
								
								src/public/app/types.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								src/public/app/types.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -296,6 +296,7 @@ declare global { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     interface CKNode { |     interface CKNode { | ||||||
|  |         _children: CKNode[]; | ||||||
|         name: string; |         name: string; | ||||||
|         childCount: number; |         childCount: number; | ||||||
|         isEmpty: boolean; |         isEmpty: boolean; | ||||||
|  | |||||||
| @ -101,10 +101,30 @@ function initTextEditor(textEditor: TextEditor) { | |||||||
|         const changes = document.differ.getChanges(); |         const changes = document.differ.getChanges(); | ||||||
|         let dirtyCodeBlocks = new Set<CKNode>(); |         let dirtyCodeBlocks = new Set<CKNode>(); | ||||||
| 
 | 
 | ||||||
|  |         function lookForCodeBlocks(node: CKNode) { | ||||||
|  |             for (const child of node._children) { | ||||||
|  |                 if (child.is("element", "paragraph")) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (child.is("element", "codeBlock")) { | ||||||
|  |                     dirtyCodeBlocks.add(child); | ||||||
|  |                 } else if (child.childCount > 0) { | ||||||
|  |                     lookForCodeBlocks(child); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         for (const change of changes) { |         for (const change of changes) { | ||||||
|             dbg("change " + JSON.stringify(change)); |             dbg("change " + JSON.stringify(change)); | ||||||
| 
 | 
 | ||||||
|             if (change.type == "insert" && change.name == "codeBlock") { |             if (change.name !== "paragraph" && change.name !== "codeBlock" && change.position.nodeAfter?.childCount > 0) { | ||||||
|  |                 /* | ||||||
|  |                  * We need to look for code blocks recursively, as they can be placed within a <div> due to | ||||||
|  |                  * general HTML support or normally underneath other elements such as tables, blockquotes, etc. | ||||||
|  |                  */ | ||||||
|  |                 lookForCodeBlocks(change.position.nodeAfter); | ||||||
|  |             } else if (change.type == "insert" && change.name == "codeBlock") { | ||||||
|                 // A new code block was inserted
 |                 // A new code block was inserted
 | ||||||
|                 const codeBlock = change.position.nodeAfter; |                 const codeBlock = change.position.nodeAfter; | ||||||
|                 // Even if it's a new codeblock, it needs dirtying in case
 |                 // Even if it's a new codeblock, it needs dirtying in case
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user