From f32e5966ab598d0a7cad20e74a8d9f29edb1bdf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Thu, 17 Sep 2015 15:34:44 +0200 Subject: Console bugfix: moving inside pasted string did not work correctly. --- js/codeq/console.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/codeq/console.js b/js/codeq/console.js index d49cd19..57d5a07 100644 --- a/js/codeq/console.js +++ b/js/codeq/console.js @@ -177,7 +177,7 @@ N = classes ? classes.length : 0, i = 0, spans = [], // what to render, items are of the form {'content': string, 'cssClass': string} - entry, classSpan, jq, span, s; + entry, classSpan, jq, span, s, prefixDelta, suffixDelta, e; // seek out the first css class while (i < N) { entry = classes[i]; @@ -186,7 +186,10 @@ } if (i < N) { // render the first span - classSpan = entry.length - startCol + entry.start; + e = entry.start + entry.length; // end column of this css class + prefixDelta = entry.start < startCol ? startCol - entry.start : 0; + suffixDelta = e > endCol ? e - endCol : 0; + classSpan = entry.length - prefixDelta - suffixDelta; span = {'content': content.substr(startCol, classSpan), 'cssClass': entry.name}; spans.push(span); startCol += classSpan; @@ -194,7 +197,11 @@ // render the rest while ((startCol < endCol) && (i < N)) { entry = classes[i]; - s = content.substr(startCol, entry.length); + e = entry.start + entry.length; // end column of this css class + prefixDelta = entry.start < startCol ? startCol - entry.start : 0; + suffixDelta = e > endCol ? e - endCol : 0; + classSpan = entry.length - prefixDelta - suffixDelta; + s = content.substr(startCol, classSpan); if (entry.name === span.cssClass) { span.content += s; // join content where the class is the same } @@ -202,14 +209,14 @@ span = {'content': s, 'cssClass': entry.name}; spans.push(span); } - startCol += entry.length; + startCol += classSpan; i++; } } // render any leftover if (startCol < endCol) { entry = makeClassDescriptor('', startCol, endCol - startCol); - spans.push({'content': content.substr(startCol), 'cssClass': ''}); + spans.push({'content': content.substring(startCol, endCol), 'cssClass': ''}); } // render spans for (i = 0; i < spans.length; i++) { -- cgit v1.2.1