Skip to content

Commit 5838ad8

Browse files
committed
Fixed issue with codefragments with TrimLeft
1 parent 977a8c3 commit 5838ad8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/codefragment.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,23 @@ void CodeFragmentManager::Private::FragmentInfo::findBlockMarkers()
110110
{
111111
//printf("gotoLine(pos=%p,start=%d,target=%d) backward\n",(void*)startPos,startLine,targetLine);
112112
while (startLine>=targetLine && startPos>=startBuf && (cc=*startPos--)) { if (cc=='\n') startLine--; }
113-
startPos++;
113+
if (startPos>startBuf)
114+
{
115+
// given fragment:
116+
// line1\n
117+
// line2\n
118+
// line3
119+
// and targetLine==2 then startPos ends at character '1' of line 1 before we detect that startLine<targetLine,
120+
// so we need to advance startPos with 2 to be at the start of line2, unless we are already at the first line.
121+
startPos+=2;
122+
}
123+
//printf("result=[%s]\n",qPrint(QCString(startPos).left(20)));
114124
}
115125
else
116126
{
117127
//printf("gotoLine(pos=%p,start=%d,target=%d) forward\n",(void*)startPos,startLine,targetLine);
118128
while (startLine<targetLine && (cc=*startPos++)) { if (cc=='\n') startLine++; }
129+
//printf("result=[%s]\n",qPrint(QCString(startPos).left(20)));
119130
}
120131
return startPos;
121132
};
@@ -366,13 +377,13 @@ void CodeFragmentManager::parseCodeFragment(OutputCodeList & codeOutList,
366377
}
367378
}
368379
// use the recorded OutputCodeList from the cache to output a pre-recorded fragment
369-
auto blockKv = codeFragment->blocksById.find(blockId.str());
370-
if (blockKv!=codeFragment->blocksById.end())
380+
auto blockKv = codeFragment->blocksById.find(blockId.str());
381+
if (blockKv != codeFragment->blocksById.end())
371382
{
372383
const auto &marker = blockKv->second;
373384
int startLine = marker->lines[0];
374385
int endLine = marker->lines[1];
375-
AUTO_TRACE_ADD("replay(start={},end={})",startLine,endLine);
386+
AUTO_TRACE_ADD("replay(start={},end={}) fileContentsTrimLeft.empty()={}",startLine,endLine,codeFragment->fileContentsTrimLeft.isEmpty());
376387
if (!trimLeft || codeFragment->fileContentsTrimLeft.isEmpty()) // replay the normal version
377388
{
378389
codeFragment->recorderCodeList.get<OutputCodeRecorder>()->replay(codeOutList,startLine+1,endLine,showLineNumbers);

0 commit comments

Comments
 (0)