Skip to content

Commit 2e4f6cc

Browse files
kubaflojfversluis
authored andcommitted
[iOS] Pasting long text when the editor has a max length
1 parent af302b6 commit 2e4f6cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Core/src/Core/Extensions/ITextInputExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public static bool TextWithinMaxLength(this ITextInput textInput, string? text,
3939

4040
var newLength = currLength + addLength - remLength;
4141

42-
return newLength <= textInput.MaxLength;
42+
var shouldChange = newLength <= textInput.MaxLength;
43+
44+
// cut text when user is pasting a text longer that maxlength
45+
if(!shouldChange && !string.IsNullOrWhiteSpace(replacementString) && replacementString!.Length >= textInput.MaxLength)
46+
textInput.Text = replacementString!.Substring(0, textInput.MaxLength);
47+
48+
return shouldChange;
4349
}
4450
#endif
4551

0 commit comments

Comments
 (0)