| 77 | * Standard implementation of the IStringDiffModel interface. |
| 78 | */ |
| 79 | export class StringDiffModel implements IStringDiffModel { |
| 80 | /** |
| 81 | * StringDiffModel constructor. |
| 82 | * |
| 83 | * Will translate additions and deletions from absolute |
| 84 | * coordinates, into {line, ch} based coordinates. |
| 85 | * Both should be sorted on the `from` position before passing. |
| 86 | * |
| 87 | * Collapsible and collapsed both defaults to false. |
| 88 | */ |
| 89 | constructor( |
| 90 | public base: string | null, |
| 91 | remote: string | null, |
| 92 | additions: DiffRangeRaw[], |
| 93 | deletions: DiffRangeRaw[], |
| 94 | collapsible?: boolean, |
| 95 | header?: string, |
| 96 | collapsed?: boolean, |
| 97 | ) { |
| 98 | this._remote = remote; |
| 99 | if (base === null) { |
| 100 | console.assert(deletions.length === 0); |
| 101 | this.deletions = []; |
| 102 | } else { |
| 103 | this.deletions = raw2Pos(deletions, base); |
| 104 | } |
| 105 | if (remote === null) { |
| 106 | console.assert(additions.length === 0); |
| 107 | this.additions = []; |
| 108 | } else { |
| 109 | this.additions = raw2Pos(additions, remote); |
| 110 | } |
| 111 | |
| 112 | this.collapsible = collapsible === true; |
| 113 | if (this.collapsible) { |
| 114 | this.collapsibleHeader = header ? header : ''; |
| 115 | this.startCollapsed = collapsed === true; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | iterateDiffs(): StringDiffModel.DiffIter { |
| 120 | return new StringDiffModel.DiffIter(this); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Chunk additions/deletions into line-based chunks |
| 125 | */ |
| 126 | getLineChunks(): Chunk[] { |
| 127 | let chunker = new LineChunker(); |
| 128 | let i = this.iterateDiffs(); |
| 129 | for (let v = i.next(); v !== undefined; v = i.next()) { |
| 130 | chunker.addDiff(v.range, v.isAddition); |
| 131 | } |
| 132 | return chunker.chunks; |
| 133 | } |
| 134 | |
| 135 | get remote(): string | null { |
| 136 | return this._remote; |
nothing calls this directly
no outgoing calls
no test coverage detected