Skip to content

Commit

Permalink
flush the undo list when the cocoa text input client is canceled.
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Jan 2, 2025
1 parent db752c1 commit 59f79cd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions vstgui/lib/ctexteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ struct TextEditorView : public CView,
void doRedo () const;
template<bool iterateForward>
void doUndoRedo () const;
void flushUndoList () const;

private:
template<typename Proc>
Expand Down Expand Up @@ -2898,6 +2899,13 @@ bool TextEditorView::gotoLine (size_t lineNo) const
return true;
}

//------------------------------------------------------------------------
void TextEditorView::flushUndoList () const
{
if (md.undoPos != md.undoList.end ())
md.undoList.erase (md.undoPos, md.undoList.end ());
}

//------------------------------------------------------------------------
void TextEditorView::checkCurrentUndoGroup (bool force) const
{
Expand Down Expand Up @@ -2926,8 +2934,7 @@ CharT* TextEditorView::createUndoRecord (size_t pos, size_t insertLen, size_t de
if (md.undoPos != md.undoList.end ())
{
md.undoPos++;
if (md.undoPos != md.undoList.end ())
md.undoList.erase (md.undoPos, md.undoList.end ());
flushUndoList ();
}
md.currentUndoGroup.record.emplace_back (UndoRecord {});
auto& record = md.currentUndoGroup.record.back ();
Expand Down Expand Up @@ -3011,6 +3018,8 @@ void TextEditorView::doRedo () const
void TextEditorView::CocoaTextInputClient::insertText (const std::u32string& string,
TextRange range)
{
if (markedText.empty () == false)
view.doUndo ();
if (range.length > 0 && range.position < view.md.model.text.size ())
{
view.md.editState.select_start = static_cast<int> (range.position);
Expand Down Expand Up @@ -3177,7 +3186,10 @@ void TextEditorView::CocoaTextInputClient::setCancelCallback (
void TextEditorView::CocoaTextInputClient::cancel ()
{
if (hasMarkedText ())
{
view.doUndo ();
view.flushUndoList ();
}
unmarkText ();
if (cancelCallback)
cancelCallback ();
Expand Down

0 comments on commit 59f79cd

Please sign in to comment.