Auto Suggestion for links to nested subheadings does not work when headings have [[ in the name

When I invoke the link suggestion modal, it fails to list any headings if the parent heading contains an existing link.

Steps to reproduce

The example note:

[[#Normal Heading 1#Normal Heading 3]]
[[#2024-06-27#

# Normal Heading 1
## Normal Heading 2
### Normal Heading 3



# [[2024-06-27]]
## heading 2 under date
### heading 3 under date
  1. copy the example note
  2. invoke the heading link to line 10 # [[2024-06-27]]
  3. notice there’s no suggestions for any nested headings

Did you follow the troubleshooting guide?

Yes, tried it in the sandbox vault

Expected result

CleanShot 2024-06-27 at 15.09.41

This screenshot shows what I’d expect to see from the dropdown modal. Normal Heading 2 and Normal Heading 3 is show.

Actual result

CleanShot 2024-06-27 at 15.09.50

In this screenshot, it seems like Obsidian recognizes 2024-06-27 as a heading (stripping [[), but when suggesting, it doesn’t know there’s nested headings.

I haven’t tested other characters, but my guess is any formatting characters cause the same issue as well.

Environment

SYSTEM INFO:
	Obsidian version: v1.6.5
	Installer version: v1.5.3
	Operating system: Darwin Kernel Version 21.6.0: Wed Apr 24 06:02:02 PDT 2024; root:xnu-8020.240.18.708.4~1/RELEASE_X86_64 21.6.0
	Login status: logged in
	Catalyst license: vip
	Insider build toggle: on
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none

Formatting characters do not cause the issue - they are taken over in the display text. The auto suggestion algorithm thus continues to recognize the text elsewhere in the document. In the case of a link, the characters are removed, thus the string becomes different: # [[2024… becomes # 2024…. The code for retrieving the auto suggestions would need to be complicated somewhat to account for that possibility.