How to use the superstring.Patch function in superstring

To help you get started, we’ve selected a few superstring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atom / text-buffer / src / display-layer.js View on Github external
// Indent guides on sequences of blank lines are affected by the content of
    // adjacent lines.
    if (this.showIndentGuides) {
      while (startRow > 0) {
        if (this.buffer.lineLengthForRow(startRow - 1) > 0) break
        startRow--
      }

      while (newEndRow < this.buffer.getLastRow()) {
        if (this.buffer.lineLengthForRow(newEndRow + 1) > 0) break
        oldEndRow++
        newEndRow++
      }
    }

    const combinedChanges = new Patch()
    this.indexedBufferRowCount += newEndRow - oldEndRow
    const {start, oldExtent, newExtent} = this.updateSpatialIndex(startRow, oldEndRow + 1, newEndRow + 1, Infinity)
    combinedChanges.splice(start, oldExtent, newExtent)

    for (let bufferRange of this.textDecorationLayer.getInvalidatedRanges()) {
      bufferRange = Range.fromObject(bufferRange)
      this.populateSpatialIndexIfNeeded(bufferRange.end.row + 1, Infinity)
      const startBufferRow = this.findBoundaryPrecedingBufferRow(bufferRange.start.row)
      const endBufferRow = this.findBoundaryFollowingBufferRow(bufferRange.end.row + 1)
      const startRow = this.translateBufferPositionWithSpatialIndex(Point(startBufferRow, 0), 'backward').row
      const endRow = this.translateBufferPositionWithSpatialIndex(Point(endBufferRow, 0), 'backward').row
      const extent = Point(endRow - startRow, 0)
      spliceArray(this.cachedScreenLines, startRow, extent.row, new Array(extent.row))
      combinedChanges.splice(Point(startRow, 0), extent, extent)
    }
github atom / text-buffer / src / helpers.js View on Github external
exports.patchFromChanges = function (changes) {
  const patch = new Patch()
  for (let i = 0; i < changes.length; i++) {
    const {oldStart, oldEnd, oldText, newStart, newEnd, newText} = changes[i]
    const oldExtent = traversal(oldEnd, oldStart)
    const newExtent = traversal(newEnd, newStart)
    patch.splice(newStart, oldExtent, newExtent, oldText, newText)
  }
  return patch
}
github atom / text-buffer / src / display-layer.js View on Github external
this.foldsMarkerLayer = params.foldsMarkerLayer || buffer.addMarkerLayer({
      maintainHistory: false,
      persistent: true,
      destroyInvalidatedMarkers: true
    })
    this.foldIdCounter = params.foldIdCounter || 1

    if (params.spatialIndex) {
      this.spatialIndex = params.spatialIndex
      this.tabCounts = params.tabCounts
      this.screenLineLengths = params.screenLineLengths
      this.rightmostScreenPosition = params.rightmostScreenPosition
      this.indexedBufferRowCount = params.indexedBufferRowCount
    } else {
      this.spatialIndex = new Patch({mergeAdjacentHunks: false})
      this.tabCounts = []
      this.screenLineLengths = []
      this.rightmostScreenPosition = Point(0, 0)
      this.indexedBufferRowCount = 0
    }
  }

superstring

A data structure to efficiently represent the results of applying patches.

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis