tdf#160539 Quickfind sidebar: Words are cut-off at beginning and end

Adjust the search finds list entry text subview of paragraph text
around the search find to start and end at a pseudo word boundary.

Change-Id: Ib1e94b0fa7f5b3f557a19259b1c83bf43ca6fa14
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168355
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
This commit is contained in:
Jim Raykowski 2024-06-02 18:23:10 -08:00
parent 4e21f1df31
commit 200f74b800

View file

@ -161,19 +161,65 @@ void QuickFindPanel::FillSearchFindsList()
auto nMarkIndex = rPaM.GetMark()->nContent.GetIndex();
auto nPointIndex = rPaM.GetPoint()->nContent.GetIndex();
// determine the text node text subview start index for the list entry text
auto nStartIndex = nMarkIndex - 50;
if (nStartIndex < 0)
nStartIndex = 0;
auto nEndIndex = nPointIndex + 50;
if (nEndIndex > sNodeText.getLength())
{
nEndIndex = sNodeText.getLength();
nStartIndex = 0;
}
else
{
// tdf#160539 format search finds results also to word boundaries
sal_Unicode ch;
do
{
ch = sNodeText[nStartIndex];
} while (++nStartIndex < nMarkIndex && ch != ' ' && ch != '\t');
if (nStartIndex < nMarkIndex)
{
// move past neighboring space and tab characters
ch = sNodeText[nStartIndex];
while (nStartIndex < nMarkIndex && (ch == ' ' || ch == '\t'))
ch = sNodeText[++nStartIndex];
}
if (nStartIndex == nMarkIndex) // no white space found
nStartIndex = nMarkIndex - 50;
}
// determine the text node text subview end index for the list entry text
auto nEndIndex = nPointIndex + 50;
if (nEndIndex >= sNodeText.getLength())
{
nEndIndex = sNodeText.getLength() - 1;
}
else
{
// tdf#160539 format search finds results also to word boundaries
sal_Unicode ch;
do
{
ch = sNodeText[nEndIndex];
} while (--nEndIndex > nPointIndex && ch != ' ' && ch != '\t');
if (nEndIndex > nPointIndex)
{
// move past neighboring space and tab characters
ch = sNodeText[nEndIndex];
while (nEndIndex > nPointIndex && (ch == ' ' || ch == '\t'))
ch = sNodeText[--nEndIndex];
}
if (nEndIndex == nPointIndex) // no white space found
{
nEndIndex = nPointIndex + 50;
if (nEndIndex >= sNodeText.getLength())
nEndIndex = sNodeText.getLength() - 1;
}
}
auto nCount = nMarkIndex - nStartIndex;
OUString sTextBeforeFind = OUString::Concat(sNodeText.subView(nStartIndex, nCount));
auto nCount1 = nPointIndex - nMarkIndex;
OUString sFind = OUString::Concat(sNodeText.subView(nMarkIndex, nCount1));
auto nCount2 = nEndIndex - nPointIndex;
auto nCount2 = nEndIndex - nPointIndex + 1;
OUString sTextAfterFind = OUString::Concat(sNodeText.subView(nPointIndex, nCount2));
OUString sStr = sTextBeforeFind + "[" + sFind + "]" + sTextAfterFind;