カーソルを配置し、範囲を選択し、テキストを削除するには、RichTextArea でカーソル コントロールが必要なようです。
この機能は gwt RichTextArea にはありませんが、長い議論、いくつかのパッチ、およびそれを実装するライブラリ (gwt-selection)がある問題があります。gwt のメンテナーが最近活動していないすべての問題を削除しているため、問題は最近クローズされましたが、再オープンするか、所有者に ping を実行してください。このライブラリを使用すると、ドキュメントの一部を取得して、書式タグを削除せずに削除できます。
とにかく、完全なテキストを削除し、すべてのコンテンツにデフォルトの css を設定する必要がある場合は、RichTextArea iframe のボディをスタイルすることができます。
gwtqueryを使用すると、コンテンツの本文をスタイルに合わせて簡単に取得できます。
import static com.google.gwt.query.client.GQuery.*;
[...]
// First attach the widget to the DOM
RootPanel.get().add(richTextArea);
// We only can manipulate the body, once the iframe document has been created,
// and this happens after it has been attached.
// Because richtTextArea uses a timeout to initialize we need a delay.
$(richTextArea)
.delay(1,
lazy()
.contents().find("body")
.css("font-name", "verdana")
.css("font-size", "x-small")
.css("color", "gray")
.done());
gwtquery をインポートせずに同じことをしたい場合は、RichTextArea がアタッチされて初期化された後に body 要素を取得するための jsni が必要です。
// First attach the widget to the DOM
RootPanel.get().add(richTextArea);
// We only can manipulate the body, once the iframe document has been created,
// and this happens after it has been attached.
// Using a timer because richtTextArea uses a timeout to initialize
new Timer() {
// There is no method to get the body, so we use JSNI
private native Element getBodyElement(Element iframe) /*-{
return iframe.contentWindow.document.body;
}-*/;
public void run() {
Element e = getBodyElement(richTextArea.getElement());
e.getStyle().setProperty("fontName", "Verdana");
e.getStyle().setProperty("fontSize", "x-small");
e.getStyle().setProperty("color", "gray");
}
}.schedule(1);