File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -351,5 +351,13 @@ describe('Parser', function() {
351351 } ) ;
352352 } ) ;
353353
354- } ) ;
355354
355+ describe ( 'latestChild()' , function ( ) {
356+ it ( 'returns the deepest last child' , function ( ) {
357+ var source = linkWithSpan ;
358+ var target = document . createTextNode ( 'bar' ) ;
359+ expect ( parser . latestChild ( source ) . isEqualNode ( target ) ) . toEqual ( true ) ;
360+ } ) ;
361+ } ) ;
362+
363+ } ) ;
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ var behavior = (function() {
119119 return ;
120120
121121 if ( container . childNodes . length > 0 )
122- cursor . moveAtEnd ( container ) ;
122+ cursor . moveAtTextEnd ( container ) ;
123123 else
124124 cursor . moveAtBeginning ( container ) ;
125125 cursor . setSelection ( ) ;
@@ -153,7 +153,7 @@ var behavior = (function() {
153153 case 'before' :
154154 previous = block . previous ( element ) ;
155155 if ( previous ) {
156- cursor . moveAtEnd ( previous ) ;
156+ cursor . moveAtTextEnd ( previous ) ;
157157 cursor . setSelection ( ) ;
158158 }
159159 break ;
Original file line number Diff line number Diff line change @@ -147,6 +147,10 @@ var Cursor = (function() {
147147 if ( this . isSelection ) return new Cursor ( this . host , this . range ) ;
148148 } ,
149149
150+ moveAtTextEnd : function ( element ) {
151+ return this . moveAtEnd ( parser . latestChild ( element ) ) ;
152+ } ,
153+
150154 setHost : function ( element ) {
151155 this . host = parser . getHost ( element ) ;
152156 if ( ! this . host ) {
Original file line number Diff line number Diff line change @@ -238,6 +238,20 @@ var parser = (function() {
238238 }
239239
240240 return true ;
241+ } ,
242+
243+ /**
244+ * Return the deepest last child of a node.
245+ *
246+ * @method latestChild
247+ * @param {HTMLElement } container The container to iterate on.
248+ * @return {HTMLElement } THe deepest last child in the container.
249+ */
250+ latestChild : function ( container ) {
251+ if ( container . lastChild )
252+ return this . latestChild ( container . lastChild ) ;
253+ else
254+ return container ;
241255 }
242256 } ;
243257} ) ( ) ;
You can’t perform that action at this time.
0 commit comments