删除和插入行时如何更新 SynMemo Undo/RedoList
如果删除一行,然后将新行插入 TSynMemo,如何更新 UndoList 和 RedoList,以便可以使用 SynMemo.Undo 撤消更改?
SynMemo1.BeginUpdate;
iLineIndex := SynMemo1.Lines.IndexOf( SynMemo1.LineText );
SynMemo1.Lines.Delete( iLineIndex );
iStartTag := SourceStyleComboBox1.CurText;
iEndTag := SourceStyleComboBox1.CurText;
System.Insert( '/', iEndTag, 2 );
iHTML := iStartTag + iElement + iEndTag;
SynMemo1.Lines.Insert( iLineIndex, iHTML );
SynMemo1.EndUpdate;
编辑 我尝试了这个,但是撤消和重做无法正常工作...我的意思是在撤消之后,该行不会恢复到操作之前的状态。
StartOfBlock.Line := SynMemo1.CaretY;
StartOfBlock.Char := 0;
EndOfBlock.Line := SynMemo1.CaretY;
EndOfBlock.Char := Length( iHTML );
SynMemo1.UndoList.BeginBlock;
SynMemo1.UndoList.AddChange(crInsert, StartOfBlock, EndOfBlock, iHTML, smNormal);
SynMemo1.UndoList.EndBlock;
SynMemo1.RedoList.BeginBlock;
SynMemo1.RedoList.AddChange(crInsert, StartOfBlock, EndOfBlock, iHTML, smNormal);
SynMemo1.RedoList.EndBlock;
我找不到任何有关设置 StartOfBlock 和 EdifOfBlock 参数的指导。这两个“操作”应组合在一起,以便“组合”操作只有一次撤消和重做 - “插入和删除”选项 eoGroupUndo = True。
If you delete a line and then insert a new line into TSynMemo how do you update the UndoList and RedoList so that the change can be undone with SynMemo.Undo?
SynMemo1.BeginUpdate;
iLineIndex := SynMemo1.Lines.IndexOf( SynMemo1.LineText );
SynMemo1.Lines.Delete( iLineIndex );
iStartTag := SourceStyleComboBox1.CurText;
iEndTag := SourceStyleComboBox1.CurText;
System.Insert( '/', iEndTag, 2 );
iHTML := iStartTag + iElement + iEndTag;
SynMemo1.Lines.Insert( iLineIndex, iHTML );
SynMemo1.EndUpdate;
EDIT
I tried this but undo and redo does not work correctly... what I mean by this is after an undo the line is not restored to what it was before the actions.
StartOfBlock.Line := SynMemo1.CaretY;
StartOfBlock.Char := 0;
EndOfBlock.Line := SynMemo1.CaretY;
EndOfBlock.Char := Length( iHTML );
SynMemo1.UndoList.BeginBlock;
SynMemo1.UndoList.AddChange(crInsert, StartOfBlock, EndOfBlock, iHTML, smNormal);
SynMemo1.UndoList.EndBlock;
SynMemo1.RedoList.BeginBlock;
SynMemo1.RedoList.AddChange(crInsert, StartOfBlock, EndOfBlock, iHTML, smNormal);
SynMemo1.RedoList.EndBlock;
I can not find any guidance about setting the StartOfBlock and EdifOfBlock parameters. The two "actions" should be combined so that there is only one undo and redo for the "combined" action - "Insert and Delete" with option eoGroupUndo = True.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我没有使用过 TSynMemo,但我确实使用过 TSynEdit,我认为处理过程会类似。
这就是我进行 BlockUndo 更新的方式:
我相信
BeginUndoBlock
/EndUndoBlock
功能驻留在 TSynEdit 上,但由于 TSynMemo 实际上是从 TSynEdit 派生的,因此它应该仍然有效。While I haven't used TSynMemo, I do use TSynEdit, I think that the processing would be similar.
This is how I do BlockUndo updates:
I believe the
BeginUndoBlock
/EndUndoBlock
functionality resides on TSynEdit, but because TSynMemo actually descends from TSynEdit this should still work.