içinde konum belirleme konumu GWT RichTextArea'da denetim konumunu ayarlama yolu var mı? TextArea'da bunu yapmak için setCusrorPosition() yöntemi vardır, ancak RichTextArea'da yoktur. Belki de RichTextArea'da imleç konumunu ayarlayabilecek bir yerel JavaScript (GWT denir) var mı?GWT RichTextArea
6
A
cevap
1
Haklısınız RichTextArea setSelectionRange yöntemini sağlamaz, ancak JSNI kullanarak bir tane oluşturdum.
final RichTextArea tr = new RichTextArea();
Button b = new Button("Test");
b.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
setSelectionRange(tr.getElement(), 15, 20);
tr.setFocus(true);
}
});
RootPanel.get().add(tr);
RootPanel.get().add(b);
Not: "pos" ve "uzunluk" doğrulama kontrollerini koymak hatırlıyor musunuz sen Aşağıda
public native void setSelectionRange(Element elem, int pos, int length) /*-{
try {
var selection = null, range2 = null;
var iframeWindow = elem.contentWindow;
var iframeDocument = iframeWindow.document;
selection = iframeWindow.getSelection();
range2 = selection.getRangeAt(0);
//create new range
var range = iframeDocument.createRange();
range.setStart(selection.anchorNode, pos);
range.setEnd(selection.anchorNode, length);
//remove the old range and add the newly created range
if (selection.removeRange) { // Firefox, Opera, IE after version 9
selection.removeRange(range2);
} else {
if (selection.removeAllRanges) { // Safari, Google Chrome
selection.removeAllRanges();
}
}
selection.addRange(range);
} catch (e) {
$wnd.alert(e);
}
}-*/;
kodunun altında yöntem yazma üstünde kullanmak için, yöntem setSelectionRange() yönteminde geçiriliyor. Bu kod IE9, FF, Chrome'da test edilmiştir.
1
Bunun hala gerekli olup olmadığından emin değilim, ancak bunu tüm gün çalışmayı denedim ve sonunda bir çözüm yolumu kesmeyi başardım. Bu, yalnızca Chrome/Safari'de test edildi. Umarım birisine yardım eder.
public static native void setCursor(Element elem, int pos, int length) /*-{
var node = elem.contentWindow.document.body;
var range = elem.contentWindow.getSelection().getRangeAt(0);
var treeWalker = $doc.createTreeWalker(node, NodeFilter.SHOW_TEXT, function(node) {
var nodeRange = $doc.createRange();
nodeRange.selectNodeContents(node);
return NodeFilter.FILTER_ACCEPT;
});
var charCount = 0;
while (treeWalker.nextNode()) {
if (charCount + treeWalker.currentNode.length > pos)
break;
charCount += treeWalker.currentNode.length;
}
var newRange = elem.contentWindow.document.createRange();
newRange.setStart(treeWalker.currentNode, 1);
newRange.setEnd(treeWalker.currentNode, 1);
var selection = elem.contentWindow.getSelection();
if (selection.removeRange) { // Firefox, Opera, IE after version 9
selection.removeRange(range);
} else if (selection.removeAllRanges) { // Safari, Google Chrome
selection.removeAllRanges();
}
selection.addRange(newRange);
}-*/;
Bu kod, 28 Kasım 2016 tarihinde küçük sözdizimi hatalarını düzeltmek üzere düzeltilmiştir.
İlgili konular
- 1. gwt, gwt-rpc, ext-gwt, smart gwt arasındaki fark
- 2. GWT
- 3. GWT
- 4. GWT
- 5. GWT
- 6. GWT -
- 7. GWT
- 8. GWT
- 9. GWT kodu VEYA GWT Designer?
- 10. GWT removeClickHandler
- 11. GWT - RPC -
- 12. GWT DOM.clone
- 13. gwt düzenleyicisi
- 14. close GWT
- 15. SuggestBox'un GWT
- 16. GWT - Maven
- 17. GWT değiştirme
- 18. GWT JPA
- 19. GWT warrantyInjected()?
- 20. GWT: UIBinder
- 21. GWT barındırılan mod Spring + Eclipse + GWT Eclipse eklentisi ile çalışmaz
- 22. GWT DateBox doğrulaması
- 23. GWT CellTree seçimi
- 24. Simple GWT OpenID Örnek
- 25. GWT Eklentisi Firefox 12
- 26. GWT 2.0 Temalar?
- 27. GWT, Sproutcore veya Cappuccino
- 28. GWT oturum yönetimi
- 29. GWT: fileUpload.getFileName() & fakepath
- 30. GWT DialogBox - animasyon
Bu, GWT 2.5'te benim için çalışmıyor. İmleci hareket ettiriyor ama tahmin edilemez. Uzunluk parametresi imleç konumunu etkiler ve seçim asla bir aralık değildir, daima imleci hareket ettirir (vurgulama yok). – Zip184
Bir richtextarea yerine bir contenteditable div kullanılabilir. –