Skip to content

Commit 29a6952

Browse files
author
garry.yao
committed
Fixing #4129: [FF]Unable to remove list with Ctrl-A.
git-svn-id: https://svn.ckeditor.com/CKEditor/trunk@4034 da63caf2-3823-0410-a1e8-d69ccee00dfb
1 parent b6978d0 commit 29a6952

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

CHANGES.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ <h3>
223223
<li><a href="http://dev.fckeditor.net/ticket/4150">#4150</a> : Fixed enlarge list result incorrect at the inner boundary of block.</li>
224224
<li><a href="http://dev.fckeditor.net/ticket/4164">#4164</a> : Now it is possible to paste text
225225
in Source mode even if forcePasteAsPlainText = true.</li>
226+
<li><a href="http://dev.fckeditor.net/ticket/4129">#4129</a> : [FF]Unable to remove list with Ctrl-A.</li>
226227
</ul>
227228
<h3>
228229
CKEditor 3.0 RC</h3>

_source/core/dom/element.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,15 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype,
564564
},
565565

566566
/**
567-
* @param ignoreEmpty Skip empty text nodes.
567+
* @param {Function} evaluator Filtering the result node.
568568
*/
569-
getLast: function( ignoreEmpty ) {
570-
var $ = this.$.lastChild;
571-
if ( ignoreEmpty && $ && ( $.nodeType == CKEDITOR.NODE_TEXT ) && !CKEDITOR.tools.trim( $.nodeValue ) )
572-
return new CKEDITOR.dom.node( $ ).getPrevious( true );
573-
else
574-
return $ ? new CKEDITOR.dom.node( $ ) : null;
569+
getLast: function( evaluator ) {
570+
var last = this.$.lastChild,
571+
retval = last && new CKEDITOR.dom.node( last );
572+
if ( retval && evaluator && !evaluator( retval ) )
573+
retval = retval.getPrevious( evaluator );
574+
575+
return retval;
575576
},
576577

577578
getStyle: function( name ) {

_source/core/dom/range.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,23 @@ CKEDITOR.dom.range = function( document ) {
14081408
return false;
14091409
},
14101410

1411+
/**
1412+
* Get the single node enclosed within the range if there's one.
1413+
*/
1414+
getEnclosedNode: function() {
1415+
var walkerRange = this.clone(),
1416+
walker = new CKEDITOR.dom.walker( walkerRange ),
1417+
isNotBookmarks = CKEDITOR.dom.walker.bookmark( true ),
1418+
isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ),
1419+
evaluator = function( node ) {
1420+
return isNotWhitespaces( node ) && isNotBookmarks( node );
1421+
};
1422+
walkerRange.evaluator = evaluator;
1423+
var node = walker.next();
1424+
walker.reset();
1425+
return node && node.equals( walker.previous() ) ? node : null;
1426+
},
1427+
14111428
getTouchedStartNode: function() {
14121429
var container = this.startContainer;
14131430

_source/core/dom/walker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
264264
*/
265265
lastBackward: function() {
266266
return iterateToLast.call( this, true );
267+
},
268+
269+
reset: function() {
270+
delete this.current;
271+
this._ = {};
267272
}
268273

269274
}

_source/plugins/domiterator/plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CKEDITOR.plugins.add( 'domiterator' );
7272

7373
// Probably the document end is reached, we need a marker node.
7474
if ( !this._.lastNode ) {
75-
this._.lastNode = range.document.createText( '' );
75+
this._.lastNode = this._.docEndMarker = range.document.createText( '' );
7676
this._.lastNode.insertAfter( lastNode );
7777
}
7878

@@ -205,6 +205,7 @@ CKEDITOR.plugins.add( 'domiterator' );
205205
if ( !block ) {
206206
// If no range has been found, this is the end.
207207
if ( !range ) {
208+
this._.docEndMarker && this._.docEndMarker.remove();
208209
this._.nextNode = null;
209210
return null;
210211
}

_source/plugins/list/plugin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
346346
ranges[ 0 ].selectNodeContents( paragraph );
347347
selection.selectRanges( ranges );
348348
}
349+
// Maybe a single range there enclosing the whole list,
350+
// turn on the list state manually(#4129).
351+
else {
352+
var range = ranges.length == 1 && ranges[ 0 ],
353+
enclosedNode = range && range.getEnclosedNode();
354+
if ( enclosedNode && enclosedNode.is && this.type == enclosedNode.getName() ) {
355+
setState.call( this, editor, CKEDITOR.TRISTATE_ON );
356+
}
357+
}
349358
}
350359

351360
var bookmarks = selection.createBookmarks( true );

_source/plugins/wysiwygarea/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
165165

166166
// Inserting the padding-br before body if it's preceded by an
167167
// unexitable block.
168-
var lastNode = body.getLast( true );
168+
var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
169169
if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) ) {
170170
var paddingBlock = editor.document.createElement(
171171
( CKEDITOR.env.ie && enterMode != CKEDITOR.ENTER_BR ) ? '<br _cke_bogus="true" />' : 'br' );

_source/tests/core/dom/element.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,19 @@
542542
}
543543
},
544544

545+
// Test get last non-spaces child node.
546+
test_getLast : function()
547+
{
548+
var element = new CKEDITOR.dom.element( document.getElementById( 'append' ) );
549+
var span1 = new CKEDITOR.dom.element( 'span' );
550+
element.append( span1 );
551+
element.append( new CKEDITOR.dom.text( ' ' ) );
552+
element.append( new CKEDITOR.dom.text( ' ' ) );
553+
var last = element.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
554+
assert.areSame( span1.$, last.$ );
555+
},
556+
557+
545558
name : document.title
546559
};
547560
})() );

_source/tests/plugins/list/list.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
setRange( range, [ 1, 0, 0, 0, 0 ], true );
117117
var sel = editor.getSelection();
118118
sel.selectRanges( [ range ] );
119+
editor.selectionChange();
120+
119121
// Waiting for 'comand state' effected.
120122
this.wait( function(){
121123
// Remove list.
@@ -148,6 +150,7 @@
148150
setRange( range, [ 1, 1, 0 ], true );
149151
var sel = editor.getSelection();
150152
sel.selectRanges( [ range ] );
153+
editor.selectionChange();
151154

152155
// Waiting for 'comand state' effected.
153156
this.wait( function(){
@@ -181,6 +184,7 @@
181184
setRange( range, [ 1, 1, 0, 0 ], [ 1, 1, 1, 1 ] );
182185
var sel = editor.getSelection();
183186
sel.selectRanges( [ range ] );
187+
editor.selectionChange();
184188

185189
// Waiting for 'comand state' effected.
186190
this.wait( function(){

0 commit comments

Comments
 (0)