From 5055aab8a7c31eb6b14f19784d882a1dd43a48b2 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 7 Apr 2024 10:05:27 +0200 Subject: [PATCH] create undo steps when the key inserted is a stop char --- vstgui/lib/ctexteditor.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vstgui/lib/ctexteditor.cpp b/vstgui/lib/ctexteditor.cpp index a7d06580c..7fc3cb601 100644 --- a/vstgui/lib/ctexteditor.cpp +++ b/vstgui/lib/ctexteditor.cpp @@ -130,6 +130,12 @@ inline void replaceTabs (std::string& str, uint32_t tabWidth) } } +//------------------------------------------------------------------------ +inline bool isStopChar (char16_t character) +{ + return std::iswpunct (character) || std::iswcntrl (character) || std::iswspace (character); +}; + using String = std::u16string; using StringView = std::u16string_view; @@ -1217,6 +1223,8 @@ void TextEditorView::onKeyboardEvent (KeyboardEvent& event) auto tmp = convert (txt->getString ()); key = tmp[0]; } + if (isStopChar (key)) + checkCurrentUndoGroup (true); } if (event.virt != VirtualKey::None) { @@ -1224,11 +1232,13 @@ void TextEditorView::onKeyboardEvent (KeyboardEvent& event) { case VirtualKey::Space: { + checkCurrentUndoGroup (true); key = 0x20; break; } case VirtualKey::Tab: { + checkCurrentUndoGroup (true); key = '\t'; break; } @@ -1799,12 +1809,6 @@ void TextEditorView::onSelectionChanged (Range newSel, bool forceInvalidation) c } } -//------------------------------------------------------------------------ -inline bool isStopChar (char16_t character) -{ - return std::iswpunct (character) || std::iswcntrl (character) || std::iswspace (character); -}; - //------------------------------------------------------------------------ template inline bool findStopChar (iterator_t& it, iterator_t end) @@ -2727,7 +2731,7 @@ void TextEditorView::setFindString (String&& text) const void TextEditorView::checkCurrentUndoGroup (bool force) const { auto currentTime = getPlatformFactory ().getTicks (); - if (force || (md.currentUndoGroup.time > 0 && md.currentUndoGroup.time < currentTime - 250)) + if (force || (md.currentUndoGroup.time > 0 && md.currentUndoGroup.time < currentTime - 500)) { if (md.currentUndoGroup.record.empty ()) return;