diff --git a/specter/include/Specter/TextField.hpp b/specter/include/Specter/TextField.hpp index f1b280617..6264900fa 100644 --- a/specter/include/Specter/TextField.hpp +++ b/specter/include/Specter/TextField.hpp @@ -65,6 +65,7 @@ public: void setText(const std::string& str); void clipboardCopy(); + void clipboardCut(); void clipboardPaste(); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); diff --git a/specter/lib/TextField.cpp b/specter/lib/TextField.cpp index 1240e2175..d2ee94f52 100644 --- a/specter/lib/TextField.cpp +++ b/specter/lib/TextField.cpp @@ -237,6 +237,28 @@ void TextField::clipboardCopy() (uint8_t*)&*begin.iter(), end.iter() - begin.iter()); } +void TextField::clipboardCut() +{ + std::unique_lock lk(m_textInputLk); + + if (!m_selectionCount) + return; + + UTF8Iterator begin(m_textStr.cbegin()); + begin += m_selectionStart; + UTF8Iterator end(begin.iter()); + end += m_selectionCount; + + rootView().window()->clipboardCopy(boo::EClipboardType::UTF8String, + (uint8_t*)&*begin.iter(), end.iter() - begin.iter()); + + std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter()); + newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend()); + size_t selStart = m_selectionStart; + setText(newStr); + setCursorPos(selStart); +} + static std::string SanitizeUTF8TextLine(const char* string, size_t len) { const char* it = string;