Fix display bug with multi-matches lines
MODIFY
lib/project/result-row-view.js
lib/project/result-row-view.js
@@ -112,16 +112,19 @@ class MatchRowView {
}
generatePreviewNode({matches, replacePattern, regex}) {
- const lineText = matches[0].lineText
const subnodes = [];
- let prevEnd = 0;
+ let prevMatchEnd = matches[0].lineTextOffset;
for (const match of matches) {
const range = Range.fromObject(match.range);
+ const prefixStart = Math.max(0, prevMatchEnd - match.lineTextOffset);
const matchStart = range.start.column - match.lineTextOffset;
- const matchEnd = range.end.column - match.lineTextOffset;
- const prefix = match.lineText.slice(prevEnd, matchStart);
+ // TODO - Handle case where (prevMatchEnd < match.lineTextOffset)
+ // The solution probably needs Workspace.scan to be reworked to account
+ // for multiple matches lines first
+
+ const prefix = match.lineText.slice(prefixStart, matchStart);
let replacementText = ''
if (replacePattern && regex) {
@@ -147,10 +150,13 @@ class MatchRowView {
replacementText
)
);
- prevEnd = matchEnd;
+ prevMatchEnd = range.end.column;
}
- const suffix = lineText.slice(prevEnd);
+ const lastMatch = matches[matches.length - 1];
+ const suffix = lastMatch.lineText.slice(
+ prevMatchEnd - lastMatch.lineTextOffset
+ );
return $.span(
{className: 'preview'},

Fix display bug with multi-matches lines