mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-01 05:21:32 +08:00 
			
		
		
		
	fix TOC widget not finding the heading by index, closes #2962
This commit is contained in:
		
							parent
							
								
									c575d47f0e
								
							
						
					
					
						commit
						95bbf5f405
					
				| @ -67,26 +67,6 @@ function findHeadingNodeByIndex(parent, headingIndex) { | |||||||
|     return headingNode; |     return headingNode; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function findHeadingElementByIndex(parent, headingIndex) { |  | ||||||
|     let headingElement = null; |  | ||||||
|     for (let i = 0; i < parent.children.length; ++i) { |  | ||||||
|         const child = parent.children[i]; |  | ||||||
|         // Headings appear as flattened top level children in the DOM named as
 |  | ||||||
|         // "H" plus the level, eg "H2", "H3", "H2", etc and not nested wrt the
 |  | ||||||
|         // heading level. If a heading node is found, decrement the headingIndex
 |  | ||||||
|         // until zero is reached
 |  | ||||||
| 
 |  | ||||||
|         if (child.tagName.match(/H\d+/i) !== null) { |  | ||||||
|             if (headingIndex === 0) { |  | ||||||
|                 headingElement = child; |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|             headingIndex--; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return headingElement; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| const MIN_HEADING_COUNT = 3; | const MIN_HEADING_COUNT = 3; | ||||||
| 
 | 
 | ||||||
| export default class TocWidget extends CollapsibleWidget { | export default class TocWidget extends CollapsibleWidget { | ||||||
| @ -190,9 +170,8 @@ export default class TocWidget extends CollapsibleWidget { | |||||||
|         const isReadOnly = await this.noteContext.isReadOnly(); |         const isReadOnly = await this.noteContext.isReadOnly(); | ||||||
| 
 | 
 | ||||||
|         if (isReadOnly) { |         if (isReadOnly) { | ||||||
|             const $readonlyTextContent = await this.noteContext.getContentElement(); |             const $container = await this.noteContext.getContentElement(); | ||||||
| 
 |             const headingElement = $container.find(":header")[headingIndex]; | ||||||
|             const headingElement = findHeadingElementByIndex($readonlyTextContent[0], headingIndex); |  | ||||||
| 
 | 
 | ||||||
|             if (headingElement != null) { |             if (headingElement != null) { | ||||||
|                 headingElement.scrollIntoView(); |                 headingElement.scrollIntoView(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam