mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-12 08:23:01 +00:00
Add clipboard paste support to UIControl_TextInput and UIScene_Keyboard (#1298)
Resolved conflicts with existing fork paste implementation - adopted upstream's batch sanitize-then-insert approach over char-by-char insertion.
This commit is contained in:
parent
33a3d69fc8
commit
d446985f12
|
|
@ -216,13 +216,23 @@ UIControl_TextInput::EDirectEditResult UIControl_TextInput::tickDirectEdit()
|
|||
if (g_KBMInput.IsKeyPressed('V') && g_KBMInput.IsKeyDown(VK_CONTROL))
|
||||
{
|
||||
wstring pasted = Screen::getClipboard();
|
||||
for (size_t i = 0; i < pasted.length(); i++)
|
||||
wstring sanitized;
|
||||
sanitized.reserve(pasted.length());
|
||||
|
||||
for (wchar_t pc : pasted)
|
||||
{
|
||||
wchar_t pc = pasted[i];
|
||||
if (pc < 0x20) continue; // skip control characters
|
||||
if (m_iCharLimit > 0 && (int)m_editBuffer.length() >= m_iCharLimit) break;
|
||||
m_editBuffer.insert(m_iCursorPos, 1, pc);
|
||||
m_iCursorPos++;
|
||||
if (pc >= 0x20) // Keep printable characters
|
||||
{
|
||||
if (m_iCharLimit > 0 && (m_editBuffer.length() + sanitized.length()) >= (size_t)m_iCharLimit)
|
||||
break;
|
||||
sanitized += pc;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sanitized.empty())
|
||||
{
|
||||
m_editBuffer.insert(m_iCursorPos, sanitized);
|
||||
m_iCursorPos += (int)sanitized.length();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,19 +229,29 @@ void UIScene_Keyboard::tick()
|
|||
if (g_KBMInput.IsKeyPressed('V') && g_KBMInput.IsKeyDown(VK_CONTROL))
|
||||
{
|
||||
wstring pasted = Screen::getClipboard();
|
||||
for (size_t i = 0; i < pasted.length(); i++)
|
||||
wstring sanitized;
|
||||
sanitized.reserve(pasted.length());
|
||||
|
||||
for (wchar_t pc : pasted)
|
||||
{
|
||||
if (pc >= 0x20) // Keep printable characters
|
||||
{
|
||||
if (static_cast<int>(m_win64TextBuffer.length() + sanitized.length()) >= m_win64MaxChars)
|
||||
break;
|
||||
sanitized += pc;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sanitized.empty())
|
||||
{
|
||||
wchar_t pc = pasted[i];
|
||||
if (pc < 0x20) continue; // skip control characters
|
||||
if (static_cast<int>(m_win64TextBuffer.length()) >= m_win64MaxChars) break;
|
||||
if (m_bPCMode)
|
||||
{
|
||||
m_win64TextBuffer.insert(m_iCursorPos, 1, pc);
|
||||
m_iCursorPos++;
|
||||
m_win64TextBuffer.insert(m_iCursorPos, sanitized);
|
||||
m_iCursorPos += (int)sanitized.length();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_win64TextBuffer += pc;
|
||||
m_win64TextBuffer += sanitized;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue