tdf#57523 - Regex search "^$" finds all empty cells in given range.

Just added a condition to trigger ScTable::SearchAndReplaceEmptyCells
which already finds and replaces all empty cells.

Corrected range detection to find empty cells in data area only.
Odd behavior when selection was left or above actual data area
has been fixed.

Change-Id: I4b0cedd9d28ebdcaf580ca1bc8da780cf6342c54
Reviewed-on: https://gerrit.libreoffice.org/22766
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index d094a7e..1cef849 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -728,7 +728,7 @@ bool ScTable::SearchAndReplace(
            css::util::SearchOptions2 aSearchOptions = rSearchItem.GetSearchOptions();
            aSearchOptions.Locale = *ScGlobal::GetLocale();

            if (aSearchOptions.searchString.isEmpty())
            if (aSearchOptions.searchString.isEmpty() || ( rSearchItem.GetRegExp() && aSearchOptions.searchString.equals("^$") ) )
            {
                // Search for empty cells.
                return SearchAndReplaceEmptyCells(rSearchItem, rCol, rRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
@@ -784,15 +784,15 @@ bool ScTable::SearchAndReplaceEmptyCells(
        for ( size_t i = 0, n = aMarkedRanges.size(); i < n; ++i )
        {
            ScRange* p = aMarkedRanges[ i ];
            if (p->aStart.Col() > nColEnd || p->aStart.Row() > nRowEnd)
            if (p->aStart.Col() > nColEnd || p->aStart.Row() > nRowEnd || p->aEnd.Col() < nColStart || p->aEnd.Row() < nRowStart)
                // This range is outside the data area.  Skip it.
                continue;

            // Shrink the range into data area only.
            if (p->aStart.Col() < nColStart)
                p->aStart.SetCol(rCol);
                p->aStart.SetCol(nColStart);
            if (p->aStart.Row() < nRowStart)
                p->aStart.SetRow(rRow);
                p->aStart.SetRow(nRowStart);

            if (p->aEnd.Col() > nColEnd)
                p->aEnd.SetCol(nColEnd);