mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Convert adjacent space to nbsp when extracting range
This resolves the issue where if you selected a word and then typed to replace it, the following space would be deleted as well. Fixes #331
This commit is contained in:
parent
625d10139e
commit
9b654a82b1
1 changed files with 12 additions and 2 deletions
|
@ -97,7 +97,7 @@ var extractContentsOfRange = function ( range, common, root ) {
|
||||||
var endNode = split( endContainer, endOffset, common, root ),
|
var endNode = split( endContainer, endOffset, common, root ),
|
||||||
startNode = split( startContainer, startOffset, common, root ),
|
startNode = split( startContainer, startOffset, common, root ),
|
||||||
frag = common.ownerDocument.createDocumentFragment(),
|
frag = common.ownerDocument.createDocumentFragment(),
|
||||||
next, before, after;
|
next, before, after, beforeText, afterText;
|
||||||
|
|
||||||
// End node will be null if at end of child nodes list.
|
// End node will be null if at end of child nodes list.
|
||||||
while ( startNode !== endNode ) {
|
while ( startNode !== endNode ) {
|
||||||
|
@ -120,7 +120,17 @@ var extractContentsOfRange = function ( range, common, root ) {
|
||||||
after.nodeType === TEXT_NODE ) {
|
after.nodeType === TEXT_NODE ) {
|
||||||
startContainer = before;
|
startContainer = before;
|
||||||
startOffset = before.length;
|
startOffset = before.length;
|
||||||
before.appendData( after.data );
|
beforeText = before.data;
|
||||||
|
afterText = after.data;
|
||||||
|
|
||||||
|
// If we now have two adjacent spaces, the second one needs to become
|
||||||
|
// a nbsp, otherwise the browser will swallow it due to HTML whitespace
|
||||||
|
// collapsing.
|
||||||
|
if ( beforeText.charAt( beforeText.length - 1 ) === ' ' &&
|
||||||
|
afterText.charAt( 0 ) === ' ' ) {
|
||||||
|
afterText = ' ' + afterText.slice( 1 ); // nbsp
|
||||||
|
}
|
||||||
|
before.appendData( afterText );
|
||||||
detach( after );
|
detach( after );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue