Skip to content

Conversation

@samyakjain1908
Copy link

@samyakjain1908 samyakjain1908 commented Jan 11, 2026

Hii @antonmedv .
I had fixed the following code problem.

Problem:

The updateTitle() function uses a regex that requires a newline after the heading:
/^\n*#(.+)\n/

This causes the page title to fail updating when:

  • Heading is the last line in the document (no trailing newline)
  • Multiple spaces appear after #
  • Heading is not at the very start of the content

Example Case:

User types "# Demo Title" at EOF
Expected: Browser tab shows "Demo Title"
Actual: Browser tab shows "Textarea" (fails silently)

Solution
Updated regex to:
/^#\s*(.+)/m
With .trim() on captured text:

What This Fixes:

  • Headings at EOF (no trailing newline)
  • Multiple spaces after # are normalized
  • Multiline mode handles headings anywhere

Test cases to verify:

Before:

image

After:

image

@antonmedv
Copy link
Owner

Should the title be at the beginning of the document only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants