Example #1
0
function deleteParagraphsOnEnter(range){
  var paragraphs = withinSelection('p');

  // If we have a selection, but not multiple paragraphs,
  // then we need to build a new paragraph out of
  // the text after the selection.

  if (paragraphs.length < 2) {
    var clone = range.cloneRange();
    var within = cursorWithin('p');
    clone.setEndAfter(within.lastChild);
    var after = contentAfterSelection(within, range);
    var p = createParagraph.call(this, after);
    dom(p).insertAfter(within);
    clone.extractContents();
    clone.detach();
    selectionRange(p, 0);
    return;
  }
  
  selectionRange(paragraphs[paragraphs.length - 1], 0);
  var extract = range.extractContents();

  // remove old paragraphs
  for (var i = 1; i < paragraphs.length; i++) {
    var p = dom(paragraphs[i]);
    this.emit('removed paragraph', p.attr('name'), p);
  }
}
Example #2
0
Paragraphs.prototype.current = function(){
  var range = selection.getRangeAt(0);

  var within = function(){
    var p = cursorWithin('p');
    return p ? [this.get(p.getAttribute('name'))] : [];
  }.bind(this);

  console.log(cursorWithin('p'));

  if (range.collapsed) return within();

  var ps = withinSelection('p');
  if (ps.length) {
    return ps.map(function(el){
      return this.get(el.getAttribute('name'));
    }, this);
  } else {
    return within();
  }
}
Example #3
0
function multipleParagraphs(){
  var ps = withinSelection('p');
  if (ps.length < 2) return false;
  return ps;
}