* @describe Uses text markers in the target editor to visualize * git modifications, additions, and deletions. The current algorithm * just redraws the markers each call.
()
| 222 | * just redraws the markers each call. |
| 223 | */ |
| 224 | updateDiffs() { |
| 225 | if (this.buffer.getLength() < MAX_BUFFER_LENGTH_TO_DIFF) { |
| 226 | // Before we redraw the diffs, tear down the old markers. |
| 227 | if (this.diffs) |
| 228 | for (const diff of this.diffs) this.markers.get(diff)?.destroy(); |
| 229 | |
| 230 | this.markers.clear(); |
| 231 | |
| 232 | const text = this.buffer.getText(); |
| 233 | this.diffs = this.repository.getLineDiffs(this.editorPath, text); |
| 234 | this.diffs = this.diffs || []; // Sanitize type to array. |
| 235 | |
| 236 | for (const diff of this.diffs) { |
| 237 | const { newStart, oldLines, newLines } = diff; |
| 238 | const startRow = newStart - 1; |
| 239 | const endRow = newStart + newLines - 1; |
| 240 | |
| 241 | let mark; |
| 242 | |
| 243 | if (oldLines === 0 && newLines > 0) { |
| 244 | mark = this.markRange(startRow, endRow, 'git-line-added'); |
| 245 | } else if (newLines === 0 && oldLines > 0) { |
| 246 | if (startRow < 0) { |
| 247 | mark = this.markRange(0, 0, 'git-previous-line-removed'); |
| 248 | } else { |
| 249 | mark = this.markRange(startRow, startRow, 'git-line-removed'); |
| 250 | } |
| 251 | } else { |
| 252 | mark = this.markRange(startRow, endRow, 'git-line-modified'); |
| 253 | } |
| 254 | |
| 255 | this.markers.set(diff, mark); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | markRange(startRow, endRow, klass) { |
| 261 | if (this.editor.getBuffer().isDestroyed()) |