@@ -1701,6 +1701,42 @@ function enterEditMode(content) {
17011701 return ;
17021702 }
17031703
1704+ // Backspace at start of heading → convert to paragraph
1705+ if ( e . key === "Backspace" && ! mod ) {
1706+ const sel2 = window . getSelection ( ) ;
1707+ if ( sel2 && sel2 . rangeCount ) {
1708+ const range2 = sel2 . getRangeAt ( 0 ) ;
1709+ const block2 = range2 . startContainer . nodeType === Node . TEXT_NODE
1710+ ? range2 . startContainer . parentElement : range2 . startContainer ;
1711+ const heading = block2 ?. closest ( "h1, h2, h3, h4, h5, h6" ) ;
1712+ if ( heading && heading . closest ( "#viewer-content" ) ) {
1713+ const atStart = range2 . collapsed &&
1714+ range2 . startOffset === 0 &&
1715+ ( range2 . startContainer === heading ||
1716+ range2 . startContainer === heading . firstChild ||
1717+ ( range2 . startContainer . nodeType === Node . TEXT_NODE &&
1718+ ! range2 . startContainer . previousSibling ) ) ;
1719+ if ( atStart ) {
1720+ e . preventDefault ( ) ;
1721+ // Convert heading to <p>, preserving content
1722+ const p = document . createElement ( "p" ) ;
1723+ while ( heading . firstChild ) {
1724+ p . appendChild ( heading . firstChild ) ;
1725+ }
1726+ heading . parentNode . replaceChild ( p , heading ) ;
1727+ // Restore cursor at start of new <p>
1728+ const r = document . createRange ( ) ;
1729+ r . setStart ( p , 0 ) ;
1730+ r . collapse ( true ) ;
1731+ sel2 . removeAllRanges ( ) ;
1732+ sel2 . addRange ( r ) ;
1733+ content . dispatchEvent ( new Event ( "input" , { bubbles : true } ) ) ;
1734+ return ;
1735+ }
1736+ }
1737+ }
1738+ }
1739+
17041740 if ( e . key === "Enter" ) {
17051741 // Inside table: block Enter except on last cell or outside cells where it exits
17061742 if ( isInsideTableOrWrapper ( ) ) {
0 commit comments