diff options
author | Aleš Smodiš <aless@guru.si> | 2015-09-17 15:34:44 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-09-17 15:34:44 +0200 |
commit | f32e5966ab598d0a7cad20e74a8d9f29edb1bdf5 (patch) | |
tree | 250b21756448fd8e3c4aaeaeb767f3ad9341231a /js/codeq | |
parent | ebd7224135e2b283ff6cc58c5a54c4aaca378a0a (diff) |
Console bugfix: moving inside pasted string did not work correctly.
Diffstat (limited to 'js/codeq')
-rw-r--r-- | js/codeq/console.js | 17 |
1 files 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++) { |