删除和插入行时如何更新 SynMemo Undo/RedoList

发布于 2024-12-27 11:51:30 字数 1085 浏览 1 评论 0原文

如果删除一行,然后将新行插入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤浅笑 2025-01-03 11:51:30

虽然我没有使用过 TSynMemo,但我确实使用过 TSynEdit,我认为处理过程会类似。

这就是我进行 BlockUndo 更新的方式:

ActiveEditor.SynEditor.BeginUpdate;
try
  //This tells SynEdit to mark all upcoming changes as a single block
  ActiveEditor.SynEditor.BeginUndoBlock;  
  try

    {Any change made here is recorded for undo purposes}
    {Buffer changes (Adding/Editing/Deletion of lines),  caret pos changes, etc}

  finally
    //This completes the undo block.
    ActiveEditor.SynEditor.EndUndoBlock;
  end;
finally
  ActiveEditor.SynEditor.EndUpdate;
end;

我相信 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:

ActiveEditor.SynEditor.BeginUpdate;
try
  //This tells SynEdit to mark all upcoming changes as a single block
  ActiveEditor.SynEditor.BeginUndoBlock;  
  try

    {Any change made here is recorded for undo purposes}
    {Buffer changes (Adding/Editing/Deletion of lines),  caret pos changes, etc}

  finally
    //This completes the undo block.
    ActiveEditor.SynEditor.EndUndoBlock;
  end;
finally
  ActiveEditor.SynEditor.EndUpdate;
end;

I believe the BeginUndoBlock/EndUndoBlock functionality resides on TSynEdit, but because TSynMemo actually descends from TSynEdit this should still work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文