tdf#127588 - extend selection to the entire field if nothing is selected

If a user pastes a string to an input field that has a maximum length restriction and no text is selected in the input field, extend the selection to the respective length of the pasted string or the maximum text length of the input field in order to prevent a text truncation warning. If the user selects some text in the input field, just replace the currently selected text and show the text truncation warning as before.

Change-Id: I2115f8c6672c9c66770abfa6918cf327a7eece17
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144784
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index d58decb..e11a9ba 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -1307,6 +1307,19 @@ void Edit::ImplPaste( uno::Reference< datatransfer::clipboard::XClipboard > cons
        OUString aText;
        aData >>= aText;

        // tdf#127588 - extend selection to the entire field or paste the text
        // from the clipboard to the current position if there is no selection
        if (mnMaxTextLen < EDIT_NOLIMIT && maSelection.Len() == 0)
        {
            const sal_Int32 aTextLen = aText.getLength();
            if (aTextLen == mnMaxTextLen)
            {
                maSelection.Min() = 0;
                maSelection.Max() = mnMaxTextLen;
            } else
                maSelection.Max() = std::min<sal_Int32>(maSelection.Min() + aTextLen, mnMaxTextLen);
        }

        Selection aSelection(maSelection);
        aSelection.Normalize();
        if (ImplTruncateToMaxLen(aText, aSelection.Len()))