0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Fix zero-width space character bug.

If the node containing the zero-width space character was merged by a call to
Range#mergeInlines, the character was not being removed, making for odd cursor
movement.
This commit is contained in:
Neil Jenkins 2012-04-10 15:26:17 +10:00
parent 63a97d9b99
commit bf8598e060
3 changed files with 27 additions and 16 deletions

File diff suppressed because one or more lines are too long

View file

@ -176,20 +176,35 @@
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
var placeholderTextNode = null;
var mayRemovePlaceholder = true;
var willEnablePlaceholderRemoval = false;
var enablePlaceholderRemoval = function () {
mayRemovePlaceholder = true;
willEnablePlaceholderRemoval = false;
};
var setPlaceholderTextNode = function ( node ) {
if ( placeholderTextNode ) {
removePlaceholderTextNode( getSelection(), true );
mayRemovePlaceholder = true;
removePlaceholderTextNode();
}
if ( !willEnablePlaceholderRemoval ) {
setTimeout( enablePlaceholderRemoval, 0 );
willEnablePlaceholderRemoval = true;
}
mayRemovePlaceholder = false;
placeholderTextNode = node;
};
var removePlaceholderTextNode = function ( range, force ) {
var removePlaceholderTextNode = function () {
if ( !mayRemovePlaceholder ) { return; }
var node = placeholderTextNode,
index;
if ( !force && node.data === '\u200B' &&
( range.startContainer === node || range.endContainer === node ) ) {
return;
}
placeholderTextNode = null;
if ( node.parentNode ) {
while ( ( index = node.data.indexOf( '\u200B' ) ) > -1 ) {
node.deleteData( index, 1 );
@ -204,7 +219,7 @@
// --- Path change events ---
var updatePath = function ( range, force ) {
if ( placeholderTextNode ) {
if ( placeholderTextNode && !force ) {
removePlaceholderTextNode( range );
}
var anchor = range.startContainer,
@ -575,9 +590,7 @@
if ( range.collapsed ) {
if ( cantFocusEmptyTextNodes ) {
fixer = doc.createTextNode( '\u200B' );
setTimeout( function () {
setPlaceholderTextNode( fixer );
}, 0 );
setPlaceholderTextNode( fixer );
} else {
fixer = doc.createTextNode( '' );
}

View file

@ -3,7 +3,7 @@
( function () {
/*global Node, Text, Element, HTMLDocument, window, document, navigator,
setTimeout, editor */
editor */
"use strict";
@ -242,7 +242,7 @@ implement([ Element ], {
}
child.detach();
if ( child.nodeType === TEXT_NODE ) {
prev.appendData( child.data );
prev.appendData( child.data.replace( /\u200B/g, '' ) );
}
else {
frags.push( child.empty() );
@ -381,9 +381,7 @@ implement([ Element ], {
if ( !el.firstChild ) {
if ( cantFocusEmptyTextNodes ) {
fixer = doc.createTextNode( '\u200B' );
setTimeout( function () {
editor._setPlaceholderTextNode( fixer );
}, 0 );
editor._setPlaceholderTextNode( fixer );
} else {
fixer = doc.createTextNode( '' );
}