Fix Found line may not be centered if word wrap is on

Fix #8489, close #8516
This commit is contained in:
Udo Hoffmann 2020-07-03 15:34:45 +02:00 committed by Don HO
parent 8b93240c59
commit d18faf13fc
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -213,39 +213,18 @@ bool Searching::readBase(const TCHAR * str, int * value, int base, int size)
void Searching::displaySectionCentered(int posStart, int posEnd, ScintillaEditView * pEditView, bool isDownwards) void Searching::displaySectionCentered(int posStart, int posEnd, ScintillaEditView * pEditView, bool isDownwards)
{ {
// to make sure the found result is visible // Make sure target lines are unfolded
//When searching up, the beginning of the (possible multiline) result is important, when scrolling down the end pEditView->execute(SCI_ENSUREVISIBLE, pEditView->execute(SCI_LINEFROMPOSITION, posStart));
int testPos = isDownwards ? posEnd : posStart; pEditView->execute(SCI_ENSUREVISIBLE, pEditView->execute(SCI_LINEFROMPOSITION, posEnd));
pEditView->execute(SCI_SETCURRENTPOS, testPos); // Jump-scroll to center, if current position is out of view
auto currentlineNumberDoc = pEditView->execute(SCI_LINEFROMPOSITION, testPos); pEditView->execute(SCI_SETYCARETPOLICY, CARET_JUMPS | CARET_EVEN);
auto currentlineNumberVis = pEditView->execute(SCI_VISIBLEFROMDOCLINE, currentlineNumberDoc); // When searching up, the beginning of the (possible multiline) result is important, when scrolling down the end
pEditView->execute(SCI_ENSUREVISIBLE, currentlineNumberDoc); // make sure target line is unfolded pEditView->execute(SCI_GOTOPOS, isDownwards ? posEnd : posStart);
pEditView->execute(SCI_SETYCARETPOLICY, CARET_EVEN);
auto firstVisibleLineVis = pEditView->execute(SCI_GETFIRSTVISIBLELINE); // Move cursor to end of result and select result
auto linesVisible = pEditView->execute(SCI_LINESONSCREEN) - 1; //-1 for the scrollbar
auto lastVisibleLineVis = linesVisible + firstVisibleLineVis;
//if out of view vertically, scroll line into (center of) view
int linesToScroll = 0;
if (currentlineNumberVis < firstVisibleLineVis)
{
linesToScroll = static_cast<int>(currentlineNumberVis - firstVisibleLineVis);
//use center
linesToScroll -= static_cast<int>(linesVisible/2);
}
else if (currentlineNumberVis > lastVisibleLineVis)
{
linesToScroll = static_cast<int>(currentlineNumberVis - lastVisibleLineVis);
//use center
linesToScroll += static_cast<int>(linesVisible/2);
}
pEditView->scroll(0, linesToScroll);
//Make sure the caret is visible, scroll horizontally (this will also fix wrapping problems)
pEditView->execute(SCI_GOTOPOS, posStart);
pEditView->execute(SCI_GOTOPOS, posEnd); pEditView->execute(SCI_GOTOPOS, posEnd);
pEditView->execute(SCI_SETANCHOR, posStart); pEditView->execute(SCI_SETANCHOR, posStart);
} }