Use Scintilla's logic for deciding when to coalesce edit box changes

Scintilla's modification notifications don't expose enough information
to do a very good job of deciding when to group changes with previous
ones, but it does expose when Scintilla thinks undo groups should end,
so just use that.

This should significantly improve the behavior of undo when editing
lines in the edit box.

Originally committed to SVN as r6370.
This commit is contained in:
Thomas Goyne 2012-01-26 22:13:39 +00:00
parent d55f1622f1
commit a1ad0fa585
1 changed files with 4 additions and 8 deletions

View File

@ -207,7 +207,6 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
// Text editor // Text editor
TextEdit = new SubsTextEditCtrl(this, wxSize(300,50), wxBORDER_SUNKEN, c); TextEdit = new SubsTextEditCtrl(this, wxSize(300,50), wxBORDER_SUNKEN, c);
TextEdit->Bind(wxEVT_KEY_DOWN, &SubsEditBox::OnKeyDown, this); TextEdit->Bind(wxEVT_KEY_DOWN, &SubsEditBox::OnKeyDown, this);
TextEdit->SetUndoCollection(false);
BottomSizer = new wxBoxSizer(wxHORIZONTAL); BottomSizer = new wxBoxSizer(wxHORIZONTAL);
BottomSizer->Add(TextEdit,1,wxEXPAND,0); BottomSizer->Add(TextEdit,1,wxEXPAND,0);
@ -221,7 +220,7 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
SetSizerAndFit(MainSizer); SetSizerAndFit(MainSizer);
TextEdit->Bind(wxEVT_STC_MODIFIED, &SubsEditBox::OnChange, this); TextEdit->Bind(wxEVT_STC_MODIFIED, &SubsEditBox::OnChange, this);
TextEdit->SetModEventMask(wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT); TextEdit->SetModEventMask(wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT | wxSTC_STARTACTION);
Bind(wxEVT_COMMAND_TEXT_UPDATED, &SubsEditBox::OnLayerEnter, this, Layer->GetId()); Bind(wxEVT_COMMAND_TEXT_UPDATED, &SubsEditBox::OnLayerEnter, this, Layer->GetId());
Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &SubsEditBox::OnLayerChange, this, Layer->GetId()); Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &SubsEditBox::OnLayerChange, this, Layer->GetId());
@ -406,12 +405,9 @@ void SubsEditBox::OnKeyDown(wxKeyEvent &event) {
void SubsEditBox::OnChange(wxStyledTextEvent &event) { void SubsEditBox::OnChange(wxStyledTextEvent &event) {
if (line && TextEdit->GetText() != line->Text) { if (line && TextEdit->GetText() != line->Text) {
if (event.GetModificationType() & wxSTC_MOD_INSERTTEXT) { if (event.GetModificationType() & wxSTC_STARTACTION)
CommitText(_("insert text")); commitId = -1;
} CommitText(_("modify text"));
else {
CommitText(_("delete text"));
}
} }
} }