From 200f74b8004564d226dce5cde7d4aa2d109f258f Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Sun, 2 Jun 2024 18:23:10 -0800 Subject: [PATCH] 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 --- sw/source/uibase/sidebar/QuickFindPanel.cxx | 56 +++++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/sw/source/uibase/sidebar/QuickFindPanel.cxx b/sw/source/uibase/sidebar/QuickFindPanel.cxx index 37edbc90019a..176ae3ad2eab 100644 --- a/sw/source/uibase/sidebar/QuickFindPanel.cxx +++ b/sw/source/uibase/sidebar/QuickFindPanel.cxx @@ -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;