From 272c1007dbf07c2fd0f3e83d63df0bbdb283f950 Mon Sep 17 00:00:00 2001 From: stoppegp Date: Tue, 7 Apr 2020 20:49:36 +0200 Subject: [PATCH] authorcolor storage optimizations --- www/code/inner.js | 49 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/www/code/inner.js b/www/code/inner.js index f213b13a8..ae2fc5dd2 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -382,23 +382,29 @@ define([ // get author marks var authormarks = []; + var colorlist = []; editor.getAllMarks().forEach(function (mark) { var pos = mark.find(); var css = mark.css; if (pos !== undefined && css !== undefined) { var color = css.replace("background-color:", "").trim(); + var colorIndex = colorlist.indexOf(color); + if (colorIndex === -1) { + colorlist.push(color); + colorIndex = colorlist.length-1; + } if (pos.from.line === pos.to.line) { if ((pos.from.ch + 1) === pos.to.ch) { - authormarks.push([pos.from.line, pos.from.ch, color]); + authormarks.push([colorIndex, pos.from.line, pos.from.ch]); } else { - authormarks.push([pos.from.line, pos.from.ch, pos.to.ch, color]); + authormarks.push([colorIndex, pos.from.line, pos.from.ch, pos.to.ch]); } } else { - authormarks.push([pos.from.line, pos.from.ch, pos.to.line, pos.to.ch, color]); + authormarks.push([colorIndex, pos.from.line, pos.from.ch, pos.to.line, pos.to.ch]); } } }); - content.authormarks = authormarks; + content.authormarks = {marks: authormarks, colorlist: colorlist}; authormarksLocal = authormarks.slice(); return content; @@ -484,32 +490,31 @@ define([ editor.getAllMarks().forEach(function (marker) { marker.clear(); }); - authormarksUpdate.forEach(function (mark) { + authormarksUpdate.marks.forEach(function (mark) { var from_line; var to_line; var from_ch; var to_ch; - var mark_color; + var colorIndex = mark[0]; + if (authormarksUpdate.colorlist === undefined || (authormarksUpdate.colorlist.length < (colorIndex+1))) { return; } + var color = authormarksUpdate.colorlist[colorIndex]; if (mark.length === 3) { - from_line = mark[0]; - to_line = mark[0]; - from_ch = mark[1]; - to_ch = mark[1]+1; - mark_color = mark[2]; + from_line = mark[1]; + to_line = mark[1]; + from_ch = mark[2]; + to_ch = mark[2]+1; } else if (mark.length === 4) { - from_line = mark[0]; - to_line = mark[0]; - from_ch = mark[1]; - to_ch = mark[2]; - mark_color = mark[3]; - } else if (mark.length === 5) { - from_line = mark[0]; - to_line = mark[2]; - from_ch = mark[1]; + from_line = mark[1]; + to_line = mark[1]; + from_ch = mark[2]; to_ch = mark[3]; - mark_color = mark[4]; + } else if (mark.length === 5) { + from_line = mark[1]; + to_line = mark[3]; + from_ch = mark[2]; + to_ch = mark[4]; } - editor.markText({line: from_line, ch: from_ch}, {line: to_line, ch: to_ch}, {css: "background-color: " + mark_color}); + editor.markText({line: from_line, ch: from_ch}, {line: to_line, ch: to_ch}, {css: "background-color: " + color}); }); } framework.localChange();