MCPcopy Create free account
hub / github.com/TruthHun/BookStack / markChanges

Function markChanges

static/editor.md/lib/codemirror/addon/merge/merge.js:227–270  ·  view source on GitHub ↗
(editor, diff, type, marks, from, to, classes)

Source from the content-addressed store, hash-verified

225 }
226
227 function markChanges(editor, diff, type, marks, from, to, classes) {
228 var pos = Pos(0, 0);
229 var top = Pos(from, 0), bot = editor.clipPos(Pos(to - 1));
230 var cls = type == DIFF_DELETE ? classes.del : classes.insert;
231 function markChunk(start, end) {
232 var bfrom = Math.max(from, start), bto = Math.min(to, end);
233 for (var i = bfrom; i < bto; ++i) {
234 var line = editor.addLineClass(i, "background", classes.chunk);
235 if (i == start) editor.addLineClass(line, "background", classes.start);
236 if (i == end - 1) editor.addLineClass(line, "background", classes.end);
237 marks.push(line);
238 }
239 // When the chunk is empty, make sure a horizontal line shows up
240 if (start == end && bfrom == end && bto == end) {
241 if (bfrom)
242 marks.push(editor.addLineClass(bfrom - 1, "background", classes.end));
243 else
244 marks.push(editor.addLineClass(bfrom, "background", classes.start));
245 }
246 }
247
248 var chunkStart = 0;
249 for (var i = 0; i < diff.length; ++i) {
250 var part = diff[i], tp = part[0], str = part[1];
251 if (tp == DIFF_EQUAL) {
252 var cleanFrom = pos.line + (startOfLineClean(diff, i) ? 0 : 1);
253 moveOver(pos, str);
254 var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
255 if (cleanTo > cleanFrom) {
256 if (i) markChunk(chunkStart, cleanFrom);
257 chunkStart = cleanTo;
258 }
259 } else {
260 if (tp == type) {
261 var end = moveOver(pos, str, true);
262 var a = posMax(top, pos), b = posMin(bot, end);
263 if (!posEq(a, b))
264 marks.push(editor.markText(a, b, {className: cls}));
265 pos = end;
266 }
267 }
268 }
269 if (chunkStart <= pos.line) markChunk(chunkStart, pos.line + 1);
270 }
271
272 // Updating the gap between editor and original
273

Callers 1

updateMarksFunction · 0.85

Calls 7

startOfLineCleanFunction · 0.85
moveOverFunction · 0.85
endOfLineCleanFunction · 0.85
markChunkFunction · 0.85
posMaxFunction · 0.85
posMinFunction · 0.85
posEqFunction · 0.85

Tested by

no test coverage detected