0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Don't insert <br> inside end of <a> on enter

Fixes #271
This commit is contained in:
Neil Jenkins 2017-03-21 17:05:41 +11:00
parent 52b92abe47
commit bb593e879a
3 changed files with 15 additions and 1 deletions

View file

@ -1448,6 +1448,13 @@ var keyHandlers = {
// If this is a malformed bit of document or in a table; // If this is a malformed bit of document or in a table;
// just play it safe and insert a <br>. // just play it safe and insert a <br>.
if ( !block || /^T[HD]$/.test( block.nodeName ) ) { if ( !block || /^T[HD]$/.test( block.nodeName ) ) {
// If inside an <a>, move focus out
parent = getNearest( range.endContainer, root, 'A' );
if ( parent ) {
parent = parent.parentNode;
moveRangeBoundariesUpTree( range, parent, parent, root );
range.collapse( false );
}
insertNodeInRange( range, self.createElement( 'BR' ) ); insertNodeInRange( range, self.createElement( 'BR' ) );
range.collapse( false ); range.collapse( false );
self.setSelection( range ); self.setSelection( range );

File diff suppressed because one or more lines are too long

View file

@ -169,6 +169,13 @@ var keyHandlers = {
// If this is a malformed bit of document or in a table; // If this is a malformed bit of document or in a table;
// just play it safe and insert a <br>. // just play it safe and insert a <br>.
if ( !block || /^T[HD]$/.test( block.nodeName ) ) { if ( !block || /^T[HD]$/.test( block.nodeName ) ) {
// If inside an <a>, move focus out
parent = getNearest( range.endContainer, root, 'A' );
if ( parent ) {
parent = parent.parentNode;
moveRangeBoundariesUpTree( range, parent, parent, root );
range.collapse( false );
}
insertNodeInRange( range, self.createElement( 'BR' ) ); insertNodeInRange( range, self.createElement( 'BR' ) );
range.collapse( false ); range.collapse( false );
self.setSelection( range ); self.setSelection( range );