fix(StatusChatInput): missbehavior when text exceeds 2000 chars

Closes #5107
This commit is contained in:
Alexandra Betouni 2022-04-07 22:25:03 +03:00 committed by Iuri Matias
parent 70b6acce16
commit 8ece8e9fd1
1 changed files with 25 additions and 17 deletions

View File

@ -945,6 +945,7 @@ Rectangle {
TextArea { TextArea {
id: messageInputField id: messageInputField
property var lastClick: 0 property var lastClick: 0
property int cursorWhenPressed: 0
textFormat: Text.RichText textFormat: Text.RichText
font.pixelSize: 15 font.pixelSize: 15
font.family: Style.current.fontRegular.name font.family: Style.current.fontRegular.name
@ -958,6 +959,7 @@ Rectangle {
Keys.onPressed: { Keys.onPressed: {
keyEvent = event; keyEvent = event;
onKeyPress(event) onKeyPress(event)
cursorWhenPressed = cursorPosition;
} }
Keys.onReleased: onRelease(event) // gives much more up to date cursorPosition Keys.onReleased: onRelease(event) // gives much more up to date cursorPosition
Keys.onShortcutOverride: event.accepted = isUploadFilePressed(event) Keys.onShortcutOverride: event.accepted = isUploadFilePressed(event)
@ -1006,6 +1008,7 @@ Rectangle {
} }
} }
onTextChanged: { onTextChanged: {
if (length <= control.messageLimit) {
var symbols = ":='xX><0O;*dB8-D#%\\"; var symbols = ":='xX><0O;*dB8-D#%\\";
if ((length > 1) && (symbols.indexOf(getText((cursorPosition - 2), (cursorPosition - 1))) !== -1) if ((length > 1) && (symbols.indexOf(getText((cursorPosition - 2), (cursorPosition - 1))) !== -1)
&& (!getText((cursorPosition - 7), cursorPosition).includes("http"))) { && (!getText((cursorPosition - 7), cursorPosition).includes("http"))) {
@ -1020,6 +1023,11 @@ Rectangle {
if (text === "") { if (text === "") {
mentionsPos = []; mentionsPos = [];
} }
} else {
var removeFrom = (cursorPosition < messageLimit) ? cursorWhenPressed : messageLimit;
remove(removeFrom, cursorPosition);
}
messageLengthLimit.remainingChars = (messageLimit - length);
} }
onReleased: function (event) { onReleased: function (event) {
@ -1146,15 +1154,15 @@ Rectangle {
StyledText { StyledText {
id: messageLengthLimit id: messageLengthLimit
property int remainingChars: messageLimit - messageInputField.length property int remainingChars: -1
text: remainingChars.toString()
visible: remainingChars <= control.messageLimitVisible
color: (remainingChars <= 0) ? Style.current.danger : Style.current.textColor
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: actions.top anchors.bottom: actions.top
anchors.rightMargin: control.isStatusUpdateInput ? Style.current.padding : Style.current.radius anchors.rightMargin: control.isStatusUpdateInput ? Style.current.padding : Style.current.radius
leftPadding: Style.current.halfPadding leftPadding: Style.current.halfPadding
rightPadding: Style.current.halfPadding rightPadding: Style.current.halfPadding
visible: ((messageInputField.length >= control.messageLimitVisible) && (messageInputField.length <= control.messageLimit))
color: (remainingChars <= messageLimitVisible) ? Style.current.danger : Style.current.textColor
text: visible ? remainingChars.toString() : ""
} }
Item { Item {