【问题标题】:JavaFX: How to create an undo point on a codeAreaJavaFX:如何在 codeArea 上创建撤消点
【发布时间】:2017-10-09 01:34:39
【问题描述】:

我有一个 CodeArea (org.fxmisc.richtext.CodeArea)。它支持热键 CTRL-Z 撤消和 CTRL-Y 重做。

我在插入符号位置以编程方式插入文本。 现在当我点击撤消时,此撤消比撤消文本插入更进一步,它撤消了文件的创建,因此代码区域再次为空。

我想在插入文本之前创建一个撤消保存点。 一定有办法做到这一点(我希望!)。

public void insertText(String text) 
{
    //TODO insert code here to create an undo point
    int index = codeArea.getCaretPosition();
    codeArea.insertText(index, text);
}

【问题讨论】:

    标签: javafx editor undo redo


    【解决方案1】:

    使用UndoManager:

    public void insertText(String text) 
    {
        codeArea.getUndoManager().mark();
        int index = codeArea.getCaretPosition();
        codeArea.insertText(index, text);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-14
      • 2017-07-26
      • 2019-05-26
      • 1970-01-01
      • 2020-08-12
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多