Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

the list handling follows usual behaviour

  • Loading branch information...
commit 1182780d53c787c558bcc1e710028f1fc6eb0533 1 parent 8195279
Jonas von Andrian authored

Showing 1 changed file with 55 additions and 3 deletions. Show diff stats Hide diff stats

  1. +55 3 source/javascripts/modes/wysiwygMode.js
58 source/javascripts/modes/wysiwygMode.js
@@ -296,6 +296,26 @@
296 296 selectNodes(node);
297 297 return false;
298 298 }
  299 + var atEndOfList = false;
  300 + if(list && atEndOfList){ // prevent addition of br in current node
  301 + listItem = $(listItem) || $(node).parent('li');
  302 + selectNodes(listItem.after('<li>').next(), true);
  303 + return false;
  304 + }
  305 + }
  306 +
  307 + /** Remove invisible nodes from the end of an element
  308 + *
  309 + * @param {Node} node
  310 + */
  311 + function clearNodeEnd(node){
  312 + var child = node.lastChild;
  313 +
  314 + while(child && (/br/i.test(child.nodeName) ||
  315 + (child.nodeType === 3 && /^ *$/.test(child.textContent)))){
  316 + node.removeChild(child);
  317 + child = node.lastChild;
  318 + }
299 319 }
300 320
301 321 /**
@@ -312,7 +332,7 @@
312 332 if(checkIfDeletedAll(preview,8) === false){
313 333 return false;
314 334 }
315   - var children, atBeginningOfLI, prevIsList, nextIsList,
  335 + var children, parent, listItem, atBeginningOfLI, atBeginningOfLineInLI, prevIsList, nextIsList,
316 336 inFirstSibling = true,
317 337 block = editor.currentNodes.block,
318 338 list = editor.currentNodes.list,
@@ -331,7 +351,9 @@
331 351 inFirstSibling = false;
332 352 if(/li/i.test(node.nodeName)){
333 353 atBeginningOfLI = true;
334   - } else {
  354 + } else if(list && /br/i.test(node.previousSibling.nodeName)){
  355 + atBeginningOfLineInLI = true;
  356 + } else{
335 357 return true;
336 358 }
337 359 break;
@@ -359,8 +381,38 @@
359 381 if(prevIsList && nextIsList){
360 382 $(prev).parent().append($(next).detach().contents());
361 383 }
362   - } else if(list && atBeginningOfLI){
  384 + } else if(atBeginningOfLineInLI){ // disable List
  385 + node.parentNode.removeChild(node.previousSibling);
  386 +
  387 + node = $(node);
  388 + children = node.nextAll();
  389 + parent = node.parent('li');
  390 +
  391 + listItem = $('<li>').append(node, children);
  392 + parent.after(listItem);
  393 + selectNodes(listItem, true);
  394 +
363 395 disableList(editor);
  396 + } else if(atBeginningOfLI){ // append contents to the previous
  397 + // list item
  398 + listItem = node.previousSibling;
  399 + children = $(node).detach().contents();
  400 +
  401 + // chrome adds invisible br tags to the end of a list item on
  402 + // some enter presses. Remove them
  403 + clearNodeEnd(listItem);
  404 +
  405 + if(!children[0] || /br/i.test(children[0].nodeName)){
  406 + //add a nonbreaking (solid) space, that can be selected by a range
  407 + children[0] = document.createTextNode('\xa0') ;
  408 + }
  409 + $(listItem).append('<br>', children);
  410 +
  411 + if(children[0]){
  412 + selectNodes(children, true);
  413 + } else {
  414 + selectNodes([listItem], false);
  415 + }
364 416 }
365 417
366 418 return false;

0 comments on commit 1182780

Please sign in to comment.
Something went wrong with that request. Please try again.