Skip to content

Commit

Permalink
create undo steps when the key inserted is a stop char
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Apr 7, 2024
1 parent 28b901a commit 5055aab
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions vstgui/lib/ctexteditor.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -1217,18 +1223,22 @@ void TextEditorView::onKeyboardEvent (KeyboardEvent& event)
auto tmp = convert (txt->getString ());
key = tmp[0];
}
if (isStopChar (key))
checkCurrentUndoGroup (true);
}
if (event.virt != VirtualKey::None)
{
switch (event.virt)
{
case VirtualKey::Space:
{
checkCurrentUndoGroup (true);
key = 0x20;
break;
}
case VirtualKey::Tab:
{
checkCurrentUndoGroup (true);
key = '\t';
break;
}
Expand Down Expand Up @@ -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<bool forward, typename iterator_t>
inline bool findStopChar (iterator_t& it, iterator_t end)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5055aab

Please sign in to comment.