Fix freeze copy/pasting large amounts of text
This commit is contained in:
parent
48ec889579
commit
c37dd994d7
@ -333,21 +333,22 @@ bool TextBoxWidget::innerSendEvent(InputEvent const& event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rightSteps = 1;
|
auto calculateSteps = [&](bool dir) {
|
||||||
int leftSteps = 1;
|
if ((keyDown->mods & (KeyMod::LCtrl | KeyMod::RCtrl)) != KeyMod::NoMod || (keyDown->mods & (KeyMod::LAlt | KeyMod::RAlt)) != KeyMod::NoMod) {
|
||||||
if ((keyDown->mods & (KeyMod::LCtrl | KeyMod::RCtrl)) != KeyMod::NoMod || (keyDown->mods & (KeyMod::LAlt | KeyMod::RAlt)) != KeyMod::NoMod) {
|
int steps;
|
||||||
rightSteps = m_text.findNextBoundary(m_cursorOffset) - m_cursorOffset;
|
if (dir) // right
|
||||||
leftSteps = m_cursorOffset - m_text.findNextBoundary(m_cursorOffset, true);
|
steps = m_text.findNextBoundary(m_cursorOffset) - m_cursorOffset;
|
||||||
|
else // left
|
||||||
|
steps = m_cursorOffset - m_text.findNextBoundary(m_cursorOffset, true);
|
||||||
|
|
||||||
if (rightSteps < 1)
|
return steps < 1 ? 1 : steps;
|
||||||
rightSteps = 1;
|
}
|
||||||
if (leftSteps < 1)
|
};
|
||||||
leftSteps = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyDown->key == Key::Backspace) {
|
if (keyDown->key == Key::Backspace) {
|
||||||
|
int steps = calculateSteps(false);
|
||||||
m_repeatCode = SpecialRepeatKeyCodes::Backspace;
|
m_repeatCode = SpecialRepeatKeyCodes::Backspace;
|
||||||
for (int i = 0; i < leftSteps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
if (m_cursorOffset > 0) {
|
if (m_cursorOffset > 0) {
|
||||||
if (modText(m_text.substr(0, m_cursorOffset - 1) + m_text.substr(m_cursorOffset)))
|
if (modText(m_text.substr(0, m_cursorOffset - 1) + m_text.substr(m_cursorOffset)))
|
||||||
m_cursorOffset -= 1;
|
m_cursorOffset -= 1;
|
||||||
@ -356,16 +357,18 @@ bool TextBoxWidget::innerSendEvent(InputEvent const& event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (keyDown->key == Key::Delete) {
|
if (keyDown->key == Key::Delete) {
|
||||||
|
int steps = calculateSteps(true);
|
||||||
m_repeatCode = SpecialRepeatKeyCodes::Delete;
|
m_repeatCode = SpecialRepeatKeyCodes::Delete;
|
||||||
for (int i = 0; i < rightSteps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
if (m_cursorOffset < (int)m_text.size())
|
if (m_cursorOffset < (int)m_text.size())
|
||||||
modText(m_text.substr(0, m_cursorOffset) + m_text.substr(m_cursorOffset + 1));
|
modText(m_text.substr(0, m_cursorOffset) + m_text.substr(m_cursorOffset + 1));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (keyDown->key == Key::Left) {
|
if (keyDown->key == Key::Left) {
|
||||||
|
int steps = calculateSteps(false);
|
||||||
m_repeatCode = SpecialRepeatKeyCodes::Left;
|
m_repeatCode = SpecialRepeatKeyCodes::Left;
|
||||||
for (int i = 0; i < leftSteps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
m_cursorOffset--;
|
m_cursorOffset--;
|
||||||
if (m_cursorOffset < 0)
|
if (m_cursorOffset < 0)
|
||||||
m_cursorOffset = 0;
|
m_cursorOffset = 0;
|
||||||
@ -373,8 +376,9 @@ bool TextBoxWidget::innerSendEvent(InputEvent const& event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (keyDown->key == Key::Right) {
|
if (keyDown->key == Key::Right) {
|
||||||
|
int steps = calculateSteps(true);
|
||||||
m_repeatCode = SpecialRepeatKeyCodes::Right;
|
m_repeatCode = SpecialRepeatKeyCodes::Right;
|
||||||
for (int i = 0; i < rightSteps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
m_cursorOffset++;
|
m_cursorOffset++;
|
||||||
if (m_cursorOffset > (int)m_text.size())
|
if (m_cursorOffset > (int)m_text.size())
|
||||||
m_cursorOffset = m_text.size();
|
m_cursorOffset = m_text.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user