如果我将光标放在<p>A line of text</p>
的中间并点击,请输入我
<p>A line</p>
<p>of text</p>
这是在我的Linux开发机器上。
当我在Windows机器上运行相同的应用程序时,我得到了
<p>A line
of text</p>
即。插入\n
而不是创建额外的<p>
元素。由于\n
只是在HTML中呈现为空格,因此当我在Windows上时, enter 基本上无法正常工作。
问题:如何在Windows上输入时强制执行插入<p>
行为?
答案 0 :(得分:1)
根据java-8,Enter键被映射到&#34; insert-break&#34;采取行动。
在Windows中,此操作在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");
}
}
}
并简单地添加&#34; \ n&#34;正如你的建议。
如果您在Linux上有不同的行为,那么我猜想会在HTMLEditorKit中添加一个自定义Action以插入段落标记。
所以我建议您需要找到Action,然后将其添加到Windows平台的HTMLEditorKit中。