在 我做的Delphi资料收集查看软件 里 一直有个Bug:
就是在列选模式或者选中文本的时候有时候会出现这种错误的现象:第一次列选(有问题)
第二次列选(却正常):
试着几次想把问题解决。无奈SynEdit.pas第三方控件源文件里东西太多了,不知道问题出在哪。
一开始以为是在SetSelStart->SetBlockBegin->InvalidateLines()->InvalidateRect() API,测试后没有改善
后来看到有FillChar函数,顺藤摸瓜,发现在有Paint过程->PaintTextLines->PaintToken/PaintHighlightToken
最后才发现Bug所在:在PaintTextLines过程中,
只将全文成
(unselected before, selected, unselected after)三部份。
而没考虑到上面列选时把全文分成若干部份:
(unselected before,
selected, unselected after,
selected, unselected after,
.
.
.
selected, unselected after)
原来部份是://示意
{================================================================} If Not Assigned(fHighlighter) Or (Not fHighlighter.Enabled) Then Begin PaintToken(sToken, nTokenLen, 0, FirstCol, nLineSelStart); PaintToken(sToken, nTokenLen, 0, nLineSelEnd, LastCol); PaintToken(sToken, nTokenLen, 0, nLineSelStart, nLineSelEnd - 1); End Else Begin PaintHighlightToken(True); End; {================================================================} 我也不想再深入改人家的代码就稍微改成这样子: {================================================================} If Not Assigned(fHighlighter) Or (Not fHighlighter.Enabled) Then Begin //PaintToken(sToken, nTokenLen, 0, FirstCol, nLineSelStart); //PaintToken(sToken, nTokenLen, 0, nLineSelEnd, LastCol); //PaintToken(sToken, nTokenLen, 0, nLineSelStart, nLineSelEnd - 1); End Else Begin PaintHighlightToken(True); End; PaintToken(sToken, nTokenLen, 0, FirstCol, nLineSelStart); PaintToken(sToken, nTokenLen, 0, nLineSelEnd, LastCol); PaintToken(sToken, nTokenLen, 0, nLineSelStart, nLineSelEnd - 1); {================================================================}
虽然选中的行没有着色,但也不影响阅读,取消选择后着色恢复正常。