1

如果我把光标放在中间<p>A line of text</p>并点击enter我得到

<p>A line</p>
<p>of text</p>

这是在我的 Linux 开发机器上。

当我在 Windows 机器上运行相同的应用程序时,我得到

<p>A line
of text</p>

\n插入而不是创建额外的<p>元素。由于\n只是在 HTML 中呈现为一个空间,enter所以当我在 Windows 上时基本上不起作用。

问题:如何在 Windows 上强制插入<p>行为?enter

4

1 回答 1

1

According to Key Bindings the Enter key is mapped to the "insert-break" Acton.

In Windows this Action is defined in the DefaultEditorKit:

public static class InsertBreakAction extends TextAction {

    /**
     * Creates this object with the appropriate identifier.
     */
    public InsertBreakAction() {
        super(insertBreakAction);
    }

    /**
     * The operation to perform when this action is triggered.
     *
     * @param e the action event
     */
    public void actionPerformed(ActionEvent e) {
        JTextComponent target = getTextComponent(e);
        if (target != null) {
            if ((! target.isEditable()) || (! target.isEnabled())) {
                UIManager.getLookAndFeel().provideErrorFeedback(target);
                return;
            }
            target.replaceSelection("\n");
        }
    }
}

and simply adds "\n" as you suggest.

If you have different behaviour on Linux then I would guess a custom Action is added to the HTMLEditorKit to insert the paragraph tag.

So I would suggest you need to find that Action and then add it to the HTMLEditorKit in the Windows platform.

于 2018-02-15T16:18:05.290 回答