sw/source/uibase/sidebar/QuickFindPanel.cxx |   52 ++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 3 deletions(-)

New commits:
commit 200f74b8004564d226dce5cde7d4aa2d109f258f
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Sun Jun 2 18:23:10 2024 -0800
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Thu Jun 6 09:06:16 2024 +0200

    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 <rayk...@gmail.com>

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;
+            }
+            else
+            {
+                // tdf#160539 format search finds results also to word 
boundaries
+                sal_Unicode ch;
+                do
+                {
+                    ch = sNodeText[nStartIndex];
+                } while (++nStartIndex < nMarkIndex && ch != ' ' && ch != '    
');
+                if (nStartIndex < nMarkIndex)
+                {
+                    // move past neighboring space and tab characters
+                    ch = sNodeText[nStartIndex];
+                    while (nStartIndex < nMarkIndex && (ch == ' ' || ch == '   
'))
+                        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())
+            if (nEndIndex >= sNodeText.getLength())
+            {
+                nEndIndex = sNodeText.getLength() - 1;
+            }
+            else
             {
-                nEndIndex = sNodeText.getLength();
+                // tdf#160539 format search finds results also to word 
boundaries
+                sal_Unicode ch;
+                do
+                {
+                    ch = sNodeText[nEndIndex];
+                } while (--nEndIndex > nPointIndex && ch != ' ' && ch != '     
');
+                if (nEndIndex > nPointIndex)
+                {
+                    // move past neighboring space and tab characters
+                    ch = sNodeText[nEndIndex];
+                    while (nEndIndex > nPointIndex && (ch == ' ' || ch == '    
'))
+                        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;
 

Reply via email to