'use strict';

// Creates a <br>.
function br () {
  return document.createElement('br')
}

function onKeydown (e) {
  if (e.keyCode === 13)
    e.preventDefault()
}

function onInput () {
  this.selection.save()

  this.sanitizer.clean(this.elem)

  // Append a <br> if need be.
  if (!this.elem.textContent)
    this.elem.appendChild(br())

  this.selection.restore()
}

function InlineMode (Quill) {

  this.elem = Quill.elem
  this.Quill = Quill

  // Store bound event handlers for later removal.
  this.onInput = onInput.bind(Quill)

  this.elem.addEventListener('keydown', onKeydown)
  Quill.on('input', this.onInput)

  // Remove all (presumably) unwanted elements by simulating input.
  this.onInput()
}

InlineMode.prototype.destroy = function () {
  this.elem.removeEventListener('keydown', onKeydown)
  this.Quill.off('input', this.onInput)

  delete this.Quill
  delete this.elem

  return null
}

InlineMode.plugin = 'inline'

module.exports = InlineMode

@@ -178,24 +178,37 @@
 nInput () %7B%0A
+  var first%0A%0A
   this.selec
@@ -264,123 +264,787 @@
  // 
-Append a %3Cbr%3E if need be.%0A  if (!this.elem.textContent)%0A    this.elem.appendChild(br())%0A%0A  this.selection.restore()
+Remove all whitespace at the beginning of the element.%0A  first = this.elem.firstChild%0A  while (this.node.isText(first) && !first.data) %7B%0A    this.elem.removeChild(first)%0A%0A    first = this.elem.firstChild%0A  %7D%0A%0A  // Append a %3Cbr%3E if need be.%0A  if (!this.elem.textContent)%0A    this.elem.appendChild(br())%0A%0A  this.selection.restore()%0A%7D%0A%0A/**%0A * insertSpaces() is a Sanitizer filter which inserts spaces between%0A * elements; this is so that, when pasting, %22%3Cp%3EOne%3C/p%3E%3Cp%3ETwo%3C/p%3E%22%22 gets%0A * turned into %22One Two%22, not %22OneTwo%22.%0A *%0A * @param %7BElement%7D elem%0A */%0Afunction insertSpaces (elem) %7B%0A  var text%0A%0A  if (!this.selection.isMarker(elem) && elem.parentNode === this.elem &&%0A      elem.previousSibling) %7B%0A    text = document.createTextNode(' ')%0A    this.elem.insertBefore(text, elem)%0A  %7D
 %0A%7D%0A%0A
@@ -1110,21 +1110,35 @@
 his.
-Quill = 
+off = Quill.off.bind(
 Quill
+)
 %0A%0A  
@@ -1218,24 +1218,71 @@
 .bind(Quill)
+%0A  this.insertSpaces = insertSpaces.bind(Quill)
 %0A%0A  this.ele
@@ -1357,16 +1357,64 @@
 Input)%0A%0A
+  Quill.sanitizer.addFilter(this.insertSpaces)%0A%0A
   // Rem
@@ -1451,16 +1451,47 @@
 elements
+ present on initialization%0A  //
  by simu
@@ -1630,22 +1630,16 @@
 %0A  this.
-Quill.
 off('inp
@@ -1672,21 +1672,19 @@
 te this.
-Quill
+off
 %0A  delet

Replace new elements with spaces in inline mode.