vcl/source/control/edit.cxx |   13 +++++++++++++
 1 file changed, 13 insertions(+)

New commits:
commit 68c4dbcebed057084083b968f244b8c430a4dc60
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Fri Dec 23 17:10:54 2022 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Mon Dec 26 12:03:46 2022 +0000

    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.heini...@yahoo.de>

diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index d58decb6fedd..e11a9bae45fa 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()))

Reply via email to