|
|
@ -20,12 +20,25 @@ define([ |
|
|
var debug = function () {}; |
|
|
var debug = function () {}; |
|
|
|
|
|
|
|
|
var MARK_OPACITY = 0.5; |
|
|
var MARK_OPACITY = 0.5; |
|
|
|
|
|
var DEFAULT = { |
|
|
|
|
|
authors: {}, |
|
|
|
|
|
marks: [[-1, 0, 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]] |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Messages.cba_writtenBy = 'Written by <em>{0}</em>'; // XXX
|
|
|
Messages.cba_writtenBy = 'Written by <em>{0}</em>'; // XXX
|
|
|
|
|
|
|
|
|
var addMark = function (Env, from, to, uid) { |
|
|
var addMark = function (Env, from, to, uid) { |
|
|
if (!Env.enabled) { return; } |
|
|
if (!Env.enabled) { return; } |
|
|
var author = Env.authormarks.authors[uid] || {}; |
|
|
var author = Env.authormarks.authors[uid] || {}; |
|
|
|
|
|
if (uid === -1) { |
|
|
|
|
|
return void Env.editor.markText(from, to, { |
|
|
|
|
|
css: "background-color: transparent", |
|
|
|
|
|
attributes: { |
|
|
|
|
|
'data-type': 'authormark', |
|
|
|
|
|
'data-uid': uid |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
uid = Number(uid); |
|
|
uid = Number(uid); |
|
|
var name = Util.fixHTML(author.name || Messages.anonymous); |
|
|
var name = Util.fixHTML(author.name || Messages.anonymous); |
|
|
var col = Util.hexToRGB(author.color); |
|
|
var col = Util.hexToRGB(author.color); |
|
|
@ -73,8 +86,8 @@ define([ |
|
|
|
|
|
|
|
|
var setAuthorMarks = function (Env, authormarks) { |
|
|
var setAuthorMarks = function (Env, authormarks) { |
|
|
authormarks = authormarks || {}; |
|
|
authormarks = authormarks || {}; |
|
|
if (!authormarks.marks) { authormarks.marks = []; } |
|
|
|
|
|
if (!authormarks.authors) { authormarks.authors = {}; } |
|
|
|
|
|
|
|
|
if (!authormarks.marks) { authormarks.marks = Util.clone(DEFAULT.marks); } |
|
|
|
|
|
if (!authormarks.authors) { authormarks.authors = Util.clone(DEFAULT.authors); } |
|
|
Env.oldMarks = Env.authormarks; |
|
|
Env.oldMarks = Env.authormarks; |
|
|
Env.authormarks = authormarks; |
|
|
Env.authormarks = authormarks; |
|
|
}; |
|
|
}; |
|
|
@ -219,8 +232,6 @@ define([ |
|
|
var toKeep = []; |
|
|
var toKeep = []; |
|
|
var toJoin = {}; |
|
|
var toJoin = {}; |
|
|
|
|
|
|
|
|
var firstMarks = first.marks.slice(); |
|
|
|
|
|
|
|
|
|
|
|
debug('error', "Fix marks"); |
|
|
debug('error', "Fix marks"); |
|
|
debug('warn', first); |
|
|
debug('warn', first); |
|
|
debug('warn', last); |
|
|
debug('warn', last); |
|
|
@ -260,15 +271,9 @@ define([ |
|
|
|
|
|
|
|
|
// If we still have markers in "first", store the last one so that we can "join"
|
|
|
// If we still have markers in "first", store the last one so that we can "join"
|
|
|
// everything at the end
|
|
|
// everything at the end
|
|
|
// NOTE: we only join if the marks were joined initially!
|
|
|
|
|
|
if (first.marks.length) { |
|
|
if (first.marks.length) { |
|
|
var idx = first.marks.length - 1; |
|
|
|
|
|
var toJoinMark = first.marks[index].slice(); |
|
|
|
|
|
|
|
|
var toJoinMark = first.marks[first.marks.length - 1].slice(); |
|
|
toJoin = parseMark(toJoinMark); |
|
|
toJoin = parseMark(toJoinMark); |
|
|
var next = parseMark(firstMarks[idx + 1]); // always an object
|
|
|
|
|
|
if (toJoin.endLine !== next.startLine || toJoin.endCh !== next.startCh) { |
|
|
|
|
|
toJoin.overlapOnly = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -310,17 +315,13 @@ define([ |
|
|
&& typeof(toJoin.endCh) !== "undefined") { |
|
|
&& typeof(toJoin.endCh) !== "undefined") { |
|
|
// Make sure the marks are joined correctly:
|
|
|
// Make sure the marks are joined correctly:
|
|
|
// fix the start position of the marks to keep
|
|
|
// fix the start position of the marks to keep
|
|
|
var overlap = toKeepEnd[0][1] < toJoin.endLine || |
|
|
|
|
|
(toKeepEnd[0][1] === toJoin.endLine && toKeepEnd[0][2] < toJoin.endCh); |
|
|
|
|
|
if (!toJoin.overlapOnly || overlap) { |
|
|
|
|
|
// Note: we must preserve the same end for this mark if it was single line!
|
|
|
|
|
|
if (typeof(toKeepEnd[0][4]) === "undefined") { // Single line
|
|
|
|
|
|
toKeepEnd[0][4] = toKeepEnd[0][3] || (toKeepEnd[0][2]+1); // preserve end ch
|
|
|
|
|
|
toKeepEnd[0][3] = toKeepEnd[0][1]; // preserve end line
|
|
|
|
|
|
} |
|
|
|
|
|
toKeepEnd[0][1] = toJoin.endLine; |
|
|
|
|
|
toKeepEnd[0][2] = toJoin.endCh; |
|
|
|
|
|
|
|
|
// Note: we must preserve the same end for this mark if it was single line!
|
|
|
|
|
|
if (typeof(toKeepEnd[0][4]) === "undefined") { // Single line
|
|
|
|
|
|
toKeepEnd[0][4] = toKeepEnd[0][3] || (toKeepEnd[0][2]+1); // preserve end ch
|
|
|
|
|
|
toKeepEnd[0][3] = toKeepEnd[0][1]; // preserve end line
|
|
|
} |
|
|
} |
|
|
|
|
|
toKeepEnd[0][1] = toJoin.endLine; |
|
|
|
|
|
toKeepEnd[0][2] = toJoin.endCh; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
debug('log', 'Fixed'); |
|
|
debug('log', 'Fixed'); |
|
|
@ -476,7 +477,7 @@ define([ |
|
|
var authormarks = Env.authormarks; |
|
|
var authormarks = Env.authormarks; |
|
|
authormarks.marks.forEach(function (mark) { |
|
|
authormarks.marks.forEach(function (mark) { |
|
|
var uid = mark[0]; |
|
|
var uid = mark[0]; |
|
|
if (!authormarks.authors || !authormarks.authors[uid]) { return; } |
|
|
|
|
|
|
|
|
if (uid !== -1 && (!authormarks.authors || !authormarks.authors[uid])) { return; } |
|
|
var from = {}; |
|
|
var from = {}; |
|
|
var to = {}; |
|
|
var to = {}; |
|
|
from.line = mark[1]; |
|
|
from.line = mark[1]; |
|
|
@ -663,10 +664,7 @@ define([ |
|
|
|
|
|
|
|
|
Markers.create = function (config) { |
|
|
Markers.create = function (config) { |
|
|
var Env = config; |
|
|
var Env = config; |
|
|
Env.authormarks = { |
|
|
|
|
|
authors: {}, |
|
|
|
|
|
marks: [] |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Env.authormarks = Util.clone(DEFAULT); |
|
|
Env.enabled = false; |
|
|
Env.enabled = false; |
|
|
Env.myAuthorId = 0; |
|
|
Env.myAuthorId = 0; |
|
|
|
|
|
|
|
|
@ -689,14 +687,16 @@ define([ |
|
|
Env.enabled = md.enableColors; |
|
|
Env.enabled = md.enableColors; |
|
|
if (!Env.enabled) { |
|
|
if (!Env.enabled) { |
|
|
// Reset marks
|
|
|
// Reset marks
|
|
|
Env.authormarks = { |
|
|
|
|
|
authors: {}, |
|
|
|
|
|
marks: [] |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Env.authormarks = {}; |
|
|
setMarks(Env); |
|
|
setMarks(Env); |
|
|
if (Env.$button) { Env.$button.hide(); } |
|
|
if (Env.$button) { Env.$button.hide(); } |
|
|
} else { |
|
|
} else { |
|
|
Env.myAuthorId = getAuthorId(Env); |
|
|
Env.myAuthorId = getAuthorId(Env); |
|
|
|
|
|
// If it's a reset, add initial marker
|
|
|
|
|
|
if (!Env.authormarks.marks || !Env.authormarks.marks.length) { |
|
|
|
|
|
Env.authormarks = Util.clone(DEFAULT); |
|
|
|
|
|
setMarks(Env); |
|
|
|
|
|
} |
|
|
if (Env.$button) { Env.$button.show(); } |
|
|
if (Env.$button) { Env.$button.show(); } |
|
|
} |
|
|
} |
|
|
if (Env.ready) { Env.framework.localChange(); } |
|
|
if (Env.ready) { Env.framework.localChange(); } |
|
|
|