在GWT中设置选定的文本(为了使复制粘贴更容易) [英] Set selected text in GWT (in order to make copy paste easier)
问题描述
更多信息:
我想要使用的应用程序是在 http://borkent-app2.appspot.com/ 。
这是我自学的希伯来语单词(我的母语是荷兰语)。希伯来语单词使用标签放置在RootPanel上。有时我想复制并粘贴希伯来词(例如,当我想在Google上搜索时),但选择它有点麻烦(可能是因为从右向左的文本方向)。所以我想通过只点击它所在的标签来选择希伯来文的文字。
public void onModuleLoad(){
final Label word = new Label(some text);
word.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event){
markText(word.getElement());
}
});
word.getElement()。setId(test);
RootPanel.get()。add(word);
$ b私有本地void markText(Element elem)/ * - {
if($ doc.selection&& $ doc.selection.createRange){
var range = $ doc.selection.createRange();
range.moveToElementText(elem);
range.select();
} else if($ doc.createRange&& $ wnd.getSelection){
var range = $ doc.createRange();
range.selectNode(elem);
var selection = $ wnd.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
} - * /;
In GWT apparently you have to use some Flash-component to alter the clipboard. Since I don't want to use Flash, but I do want to copy and paste text from my application, I would like to set text selected if someone clicks on it. The only thing the user has to do is to type Ctrl-C/Ctrl-V to copy and paste (in Windows). Is this possible? How do I do this?
More info:
The app in which I would like to use this is at http://borkent-app2.appspot.com/. It is an app I made to teach myself Hebrew words (my native language is Dutch). The Hebrew word is placed on the RootPanel using a Label. Sometimes I would like to copy and paste the Hebrew word (when I want to search on it in Google for example), but selecting it is somewhat cumbersome (probably because of the right-to-left text direction). So I would like to select the text of the Hebrew word by only clicking on the Label it is in.
Something like this?
public void onModuleLoad() {
final Label word = new Label("some text");
word.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
markText(word.getElement());
}
});
word.getElement().setId("test");
RootPanel.get().add(word);
}
private native void markText(Element elem) /*-{
if ($doc.selection && $doc.selection.createRange) {
var range = $doc.selection.createRange();
range.moveToElementText(elem);
range.select();
} else if ($doc.createRange && $wnd.getSelection) {
var range = $doc.createRange();
range.selectNode(elem);
var selection = $wnd.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
}-*/;
这篇关于在GWT中设置选定的文本(为了使复制粘贴更容易)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!