src/model/fragment.js
// Build a fragment from an array of nodes.
Build a fragment from an array of nodes.
Build a fragment from an array of nodes .
static fromArray(array) {
    if (!array.length) return emptyFragment
    let hasText = false, joined
    for (let i = 0; i < array.length; i++) {
      let node = array[i]
      if (node.isText) {
        hasText = true
        if (i && array[i - 1].sameMarkup(node)) {
          if (!joined) joined = array.slice(0, i)
          joined[joined.length - 1] = node.copy(joined[joined.length - 1].text + node.text)
          continue
        }
      }
      if (joined) joined.push(node)
    }
    return hasText ? new TextFragment(joined || array) : new FlatFragment(array)
  }
static fromArray ( array ) { if ( ! array . length ) return emptyFragment let hasText = false , joined for ( let i = 0 ; i < array . length ; i ++ ) { let node = array [ i ] if ( node . isText ) { hasText = true if ( i && array [ i - 1 ] . sameMarkup ( node ) ) { if ( ! joined ) joined = array . slice ( 0 , i ) joined [ joined . length - 1 ] = node . copy ( joined [ joined . length - 1 ] . text + node . text ) continue } } if ( joined ) joined . push ( node ) } return hasText ? new TextFragment ( joined || array ) : new FlatFragment ( array ) }
Build a fragment from an array of nodes.
Build a fragment from an array of nodes .