Skip to content

Commit 1502f80

Browse files
Todd Bermanmarijnh
authored andcommitted
Add mergeMarkerLocation to options to allow customization
1 parent b25f857 commit 1502f80

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

addon/merge/merge.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
(this.edit.state.diffViews || (this.edit.state.diffViews = [])).push(this);
4141
this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: !this.mv.options.allowEditingOriginals}, copyObj(options)));
4242
this.orig.state.diffViews = [this];
43+
this.classes.location = options.mergeMarkerLocation || "background";
4344

4445
this.diff = getDiff(asString(orig), asString(options.value));
4546
this.chunks = getChunks(this.diff);
@@ -192,14 +193,20 @@
192193
// Updating the marks for editor content
193194

194195
function clearMarks(editor, arr, classes) {
196+
function removeLineClass(l, klass) {
197+
var classList = Array.isArray(classes.location) ? classes.location : [classes.location]
198+
for (var c = 0; c < classList.length; ++c) {
199+
editor.removeLineClass(l, classList[c], klass)
200+
}
201+
}
195202
for (var i = 0; i < arr.length; ++i) {
196203
var mark = arr[i];
197204
if (mark instanceof CodeMirror.TextMarker) {
198205
mark.clear();
199206
} else if (mark.parent) {
200-
editor.removeLineClass(mark, "background", classes.chunk);
201-
editor.removeLineClass(mark, "background", classes.start);
202-
editor.removeLineClass(mark, "background", classes.end);
207+
removeLineClass(mark, classes.chunk);
208+
removeLineClass(mark, classes.start);
209+
removeLineClass(mark, classes.end);
203210
}
204211
}
205212
arr.length = 0;
@@ -231,19 +238,29 @@
231238
var top = Pos(from, 0), bot = editor.clipPos(Pos(to - 1));
232239
var cls = type == DIFF_DELETE ? classes.del : classes.insert;
233240
function markChunk(start, end) {
241+
function addLineClass(l, klass) {
242+
var classList = Array.isArray(classes.location) ? classes.location : [classes.location]
243+
var ret = null
244+
for (var c = 0; c < classList.length; ++c) {
245+
ret = editor.addLineClass(l, classList[c], klass)
246+
}
247+
248+
return ret
249+
}
250+
234251
var bfrom = Math.max(from, start), bto = Math.min(to, end);
235252
for (var i = bfrom; i < bto; ++i) {
236-
var line = editor.addLineClass(i, "background", classes.chunk);
237-
if (i == start) editor.addLineClass(line, "background", classes.start);
238-
if (i == end - 1) editor.addLineClass(line, "background", classes.end);
253+
var line = addLineClass(i, classes.chunk);
254+
if (i == start) addLineClass(line, classes.start);
255+
if (i == end - 1) addLineClass(line, classes.end);
239256
marks.push(line);
240257
}
241258
// When the chunk is empty, make sure a horizontal line shows up
242259
if (start == end && bfrom == end && bto == end) {
243260
if (bfrom)
244-
marks.push(editor.addLineClass(bfrom - 1, "background", classes.end));
261+
marks.push(addLineClass(bfrom - 1, classes.end));
245262
else
246-
marks.push(editor.addLineClass(bfrom, "background", classes.start));
263+
marks.push(addLineClass(bfrom, classes.start));
247264
}
248265
}
249266

doc/manual.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,7 @@ <h2 id="addons">Addons</h2>
25832583
<dd>Optional <code>to</code> position that will be used by <code>pick()</code> instead
25842584
of the global one passed with the full list of completions.</dd>
25852585
</dl></dd>
2586-
2586+
25872587
<dd>The plugin understands the following options (the options object
25882588
will also be passed along to the hinting function, which may
25892589
understand additional options):
@@ -2986,6 +2986,10 @@ <h2 id="addons">Addons</h2>
29862986
<dt><code><strong>showDifferences</strong>: boolean</code></dt>
29872987
<dd>When true (the default), changed pieces of text are
29882988
highlighted.</dd>
2989+
<dt><code><strong>mergeMarkerLocations</strong>: string|Array</code></dt>
2990+
<dd>By default the merge highlights are added using addLineClass with "background".
2991+
Override this to customize it to be any valid `where` parameter or an Array of valid `where`
2992+
parameters.</dd>
29892993
</dl>
29902994
The addon also defines commands <code>"goNextDiff"</code>
29912995
and <code>"goPrevDiff"</code> to quickly jump to the next

0 commit comments

Comments
 (0)