在GWT中设置选定的文本(为了使复制粘贴更容易) [英] Set selected text in GWT (in order to make copy paste easier)

查看:154
本文介绍了在GWT中设置选定的文本(为了使复制粘贴更容易)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GWT中,显然你必须使用一些Flash组件来改变剪贴板。由于我不想使用Flash,但我想从我的应用程序中复制和粘贴文本,所以如果有人点击它,我想设置选中的文本。用户唯一需要做的就是键入Ctrl-C / Ctrl-V来复制和粘贴(在Windows中)。这可能吗?我该如何做到这一点?



更多信息:



我想要使用的应用程序是在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆