【问题标题】:AvalonEdit :: How do I preserve current state in the UndoStack?AvalonEdit :: 如何在 UndoStack 中保留当前状态?
【发布时间】:2015-06-19 10:13:12
【问题描述】:

我目前正致力于在 HTML 所见即所得/“源代码”并排编辑器中实现 AvalonEdit。当用户从设计模式 (a RichTextBox) 切换到源模式 (AvalonEdit TextEditor) 时,来自 RTB 的 XAML 将转换为 HTML 并写入 TextEditor.Document.Text 属性。

这显然会清除撤消堆栈。

如何将文档的状态推送到UndoStack,以便用户可以“返回”?我尝试将写入操作包装在 RunUpdate() IDisposable 中,但这不起作用:

using (var _ = TextEditor.Document.RunUpdate())
{
   TextEditor.Document.Text = html;
}

任何帮助将不胜感激。

【问题讨论】:

    标签: avalonedit


    【解决方案1】:

    由于这已经晚了几年,我不确定它是否直接回答了这个问题。然而,当前版本的 AvalonEdit 函数设置 TextEditor.Text 将清除撤消堆栈,但修改 TextEditor.Document.Text 不会。 (这与提问者观察到的行为背道而驰,因此可能在此后的几年中发生了变化)。查看源代码,TextEditor.Document.Text 似乎执行的代码相当于

    this.Replace(0, this.TextLength, value);
    

    因此,即使在旧版本的库上,类似的调用也可能有效。

    【讨论】:

      猜你喜欢
      • 2011-11-26
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      相关资源
      最近更新 更多