Reputation: 161
we are using RichTextBox to display text. we are having issues to undo/redo with protected text.
here's the workflow, normally we have pure text and in this case undo/redo works perfectly. occasionally we need to mark certain text to be "Protected". we do the validation and convert the Rtf on the fly and do the following to assign it back to the RTB:
m_rtbText.Rtf = sRtf
the problem is after step over this line, the
m_rtbText.CanUndo
property will be set to False internally, as a result we lost all the undo steps. To give you an example, here is what it looks like before the validation:
\cf1\i0\v\f2 <PSI_START_OBJECT><PSI_MEDIA><Media2><MediaID>16346</MediaID><Name>\f3\rtlch\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9</\f2\ltrch Name><FileName>N:\\media\f3\rtlch\\\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9_1.\f2\ltrch wav</FileName><Length>00:00:33.0</Length><OutCue></OutCue><Description></Description></Media2><PSI_MID_OBJECT\f3\rtlch >\v0\f0\'c7\'e1\'ca\'de\'d1\'ed\'d1 \'c7\'e1\'c5\'ce\'c8\'c7\'d1\'ed : \cf2\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9\par
\cf1\'c7\'e1\'e3\'cf\'f8\'c9 : \cf2\f3 00:00:33.0\cf3\i\f4 .\v <\f1\ltrch PSI_END_OBJECT\f4\rtlch >\cf0\v0\f1\ltrch\par
and here's what looks like after the validation:
\cf1\i0\protect\v\f2 <PSI_START_OBJECT><PSI_MEDIA><Media2><MediaID>16346</MediaID><Name>\f3\rtlch\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9</\f2\ltrch Name><FileName>N:\\media\f3\rtlch\\\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9_1.\f2\ltrch wav</FileName><Length>00:00:33.0</Length><OutCue></OutCue><Description></Description></Media2><PSI_MID_OBJECT\f3\rtlch >\v0\f0\'c7\'e1\'ca\'de\'d1\'ed\'d1 \'c7\'e1\'c5\'ce\'c8\'c7\'d1\'ed : \cf2\'e4\'d4\'d1\'c9 \'cc\'e6\'ed\'c9\par
\cf1\'c7\'e1\'e3\'cf\'f8\'c9 : \cf2\f3 00:00:33.0\cf3\i\f4 .\v <\f1\ltrch PSI_END_OBJECT\f4\rtlch >\cf0\protect0\v0\f1\ltrch\par
as you can see, the only difference here are the 2 "protect" entries. Text wise they are exactly the same.
could this be a Microsoft bug or am I missing something? FYI we are on .NET framework 4.6.2, VS2015 Update3
Upvotes: 0
Views: 349
Reputation: 161
thanks to dlatikay, seems we cannot directly work with the Rtf assignment, doing so will cause the undo stack to be lost. the alternative way is to work with the Selected Rtf. the following code worked:
m_rtbText.SelectionStart = 0;
m_rtbText.SelectAll();
m_rtbText.SelectedRtf = sRtf;
this is basically a replace. the undo is retained.
Upvotes: 2