Page 1 of 1

Undo action bug?

Posted: Wed Mar 10, 2010 1:25 pm
by kolovan
Hello Sergey,

I want you to know that I found some kind of a bug.

There are several components on my form: ActionList (only rvActionUndo included), MainMenu (with Undo item linked to rvActionUndo), RichViewEdit and RVStyle. The only text in RVE is one text item with tag "Tag1" and text " several_useless_words ".

OnChange event handler of RVE has the next code inside:

Code: Select all

UnicodeString tag = (wchar_t *)rve1->GetCurrentTag();
if (tag.Pos(L"Tag")) {
	if (rve1->GetCurrentItemText().Trim().IsEmpty()) {
		if (!tag.Pos(L"NEW"))
			rve1->SetItemTagEd(rve1->CurItemNo,(int)StrNew((L"NEW" + tag).c_str()));
	}
	else {
		if (tag.Pos(L"NEW")) {
			rve1->SetItemTagEd(rve1->CurItemNo,(int)StrNew((tag.SubString(4,tag.Length())).c_str()));
		}
	}
}
As you can see I want to change tags of items depending on thier content. Well it works fine! But after one change of tag there appears a bug with UndoAction:
  1. I delete all letters except spaces in text item:
    text changes: " several_useless_words "->" "
    tag changes: "Tag1"->"NewTag1"
  2. I type some letters:
    text changes: " "->" Gsfasfasf "
    tag changes: "NewTag1"->"Tag1"
  3. Now I'm pressing Ctrl+Z shorcut key (or Undo menu item) until clearing of Undo buffer. And that's happened (?) when there is only one letter left:
    " Gsfasfasf "->" G "
    while menu item Undo is still available! I still can press menu item but it does nothing.
Well as far as I know when undo buffer is empty any visual component (button, menu item etc.) that linked to rvUndoAction becomes unavailable. So what can provide my problem? According to help I'm using only editing-style methods (that can be undone/redone) - SetItemTagEd.

P.S. TagsArePChars is ON; UndoLimit equals -1
P.P.S. Sorry for C++ :D

Posted: Wed Mar 10, 2010 7:00 pm
by Sergey Tkachenko
Hmm. When I added this code in OnChange (after converting it to Pascal:) ), I got a stack overflow. It is obvious because SetItemTagEd calls OnChange too.

If you want to change tag on text editing, consider using OnItemTextEdit event instead.