Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Text.getSelectionText()
Text.getSelectionText() [message #640002] Thu, 18 November 2010 16:15 Go to next message
DANIEL  is currently offline DANIEL Friend
Messages: 13
Registered: November 2010
Junior Member
I implemented a right cick context menu on a Text widget for copy using Javascript, but I found a problem in the text selection.

The getSelectionText method of the Text widget returns the selected text shifted 2 chars to the right. For example, if the text is "Hello world" and the selected text is "Hello", the getSelectionText method will return "llo W".

I tried using the setFocus() before getSelectionText but it did not help. Using the debugger I can see that the x and y are incorrect in the Text widget.

Did anyone had that problem too?
Re: Text.getSelectionText() [message #640007 is a reply to message #640002] Thu, 18 November 2010 16:22 Go to previous messageGo to next message
DANIEL  is currently offline DANIEL Friend
Messages: 13
Registered: November 2010
Junior Member
This is for sure a bug. In Mozilla Forefox the getSelectionText method returns the correct text. The problem exists only in IE.
Re: Text.getSelectionText() [message #640018 is a reply to message #640007] Thu, 18 November 2010 16:48 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Daniel,
I can't reproduce it with current CVS HEAD and Controls Demo -> Text Tab
under IE8 (Windows 7). Could you provide more information about the RAP
and IE versions used.
A snippet to reproduce it will help too.
Best,
Ivan

On 18.11.2010 6:22 PM, DANIEL wrote:
> This is for sure a bug. In Mozilla Forefox the getSelectionText
> method returns the correct text. The problem exists only in IE.
Re: Text.getSelectionText() [message #640034 is a reply to message #640018] Thu, 18 November 2010 18:29 Go to previous messageGo to next message
DANIEL  is currently offline DANIEL Friend
Messages: 13
Registered: November 2010
Junior Member
I'm using IE version 8.0.7600.16385 on Windows 7, and org.eclipse.rap.ui version 1.3.1.20100915-2301

I have a single widget in my view (Text). I created a context menu on that Text widget (not the view). One of the Action is called Copy and here what it does

String x = text.getSelectionText();
System.out.println(x);
Re: Text.getSelectionText() [message #640049 is a reply to message #640034] Thu, 18 November 2010 19:48 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Daniel,
I can't reproduce it with RAP 1.3.1 either. Please file a bugzilla with
a self-running snippet to reproduce it.
Thanks,
Ivan

On 18.11.2010 8:29 PM, DANIEL wrote:
> I'm using IE version 8.0.7600.16385 on Windows 7, and
> org.eclipse.rap.ui version 1.3.1.20100915-2301
>
> I have a single widget in my view (Text). I created a context menu on
> that Text widget (not the view). One of the Action is called Copy and
> here what it does
> String x = text.getSelectionText();
> System.out.println(x);
>
Re: Text.getSelectionText() [message #640669 is a reply to message #640049] Mon, 22 November 2010 18:39 Go to previous messageGo to next message
DANIEL  is currently offline DANIEL Friend
Messages: 13
Registered: November 2010
Junior Member
The bug exists only when you append an end of line to the Text widget. For example use text.append("This is a test line\r\n"); and then System.out.println(text.getSelectionText());

You can use the following to reproduce the problem. For example select the "test" word in the view, right click, select Copy. The output is "st li" instead of "test". If you want I can send you my test plug-in that recreates this problem.

This is the SampleView.java
package test.get.selection.views;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.part.ViewPart;

import test.get.selection.ActionCopy;
import test.get.selection.Activator;

public class SampleView extends ViewPart 
{
    public static final String ID = "test.get.selection.views.SampleView"; //$NON-NLS-1$

    private Text text;

    private RetargetAction actionCopyRetarget;
    private ActionCopy actionCopy;


    @Override
    public void createPartControl(Composite parent)
    {
        text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
        text.append("This is a test line\r\n");
       
        createActions();

        MenuManager menuManager = new MenuManager("ConsolePopupMenu"); //$NON-NLS-1$
        menuManager.setRemoveAllWhenShown(false);

        menuManager.add(actionCopyRetarget);
        menuManager.update(true);

        Menu menu = menuManager.createContextMenu(parent);
        text.setMenu(menu);
    }

    @Override
    public void setFocus()
    {
    }

    private void createActions()
    {

        IWorkbenchWindow window = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow();

        actionCopyRetarget = (RetargetAction) ActionFactory.COPY.create(window);
        actionCopy = new ActionCopy(text);
        this.getViewSite().getActionBars().setGlobalActionHandler(actionCopyRetarget.getId(), actionCopy);
    }

}


and this is the ActionCopy.java
package test.get.selection;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Text;

public class ActionCopy extends Action
{

    private final static String ACTION_ID = "test.get.selection.copyAction"; //$NON-NLS-1$

    private Text text;

    public ActionCopy(Text text)
    {
        this.text = text;
        setId(ACTION_ID);
    }

    @Override
    public void run()
    {
        System.out.println(text.getSelectionText());
    }

    public void setEnabled()
    {
        setEnabled(text.getSelectionCount() > 0);
    }

}
Re: Text.getSelectionText() [message #640697 is a reply to message #640669] Mon, 22 November 2010 20:21 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Daniel,
I can reproduce it with your snippet and IE8 under Windows 7. Please
file a bugzilla to track the progress on this issue. Please attach this
code to the bug.
Thanks,
Ivan

On 22.11.2010 8:39 PM, DANIEL wrote:
> The bug exists only when you append an end of line to the Text widget.
> For example use text.append("This is a test line\r\n"); and then
> System.out.println(text.getSelectionText());
>
> You can use the following to reproduce the problem. For example select
> the "test" word in the view, right click, select Copy. The output is
> "st li" instead of "test". If you want I can send you my test plug-in
> that recreates this problem.
>
> This is the SampleView.java
> package test.get.selection.views;
>
> import org.eclipse.jface.action.MenuManager;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Menu;
> import org.eclipse.swt.widgets.Text;
> import org.eclipse.ui.IWorkbenchWindow;
> import org.eclipse.ui.actions.ActionFactory;
> import org.eclipse.ui.actions.RetargetAction;
> import org.eclipse.ui.part.ViewPart;
>
> import test.get.selection.ActionCopy;
> import test.get.selection.Activator;
>
> public class SampleView extends ViewPart {
> public static final String ID =
> "test.get.selection.views.SampleView"; //$NON-NLS-1$
>
> private Text text;
>
> private RetargetAction actionCopyRetarget;
> private ActionCopy actionCopy;
>
>
> @Override
> public void createPartControl(Composite parent)
> {
> text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
> | SWT.READ_ONLY);
> text.append("This is a test line\r\n");
> createActions();
>
> MenuManager menuManager = new MenuManager("ConsolePopupMenu");
> //$NON-NLS-1$
> menuManager.setRemoveAllWhenShown(false);
>
> menuManager.add(actionCopyRetarget);
> menuManager.update(true);
>
> Menu menu = menuManager.createContextMenu(parent);
> text.setMenu(menu);
> }
>
> @Override
> public void setFocus()
> {
> }
>
> private void createActions()
> {
>
> IWorkbenchWindow window =
> Activator.getDefault().getWorkbench().getActiveWorkbenchWind ow();
>
> actionCopyRetarget = (RetargetAction)
> ActionFactory.COPY.create(window);
> actionCopy = new ActionCopy(text);
>
> this.getViewSite().getActionBars().setGlobalActionHandler(ac tionCopyRetarget.getId(),
> actionCopy);
> }
>
> }
>
>
> and this is the ActionCopy.java
>
> package test.get.selection;
>
> import org.eclipse.jface.action.Action;
> import org.eclipse.swt.widgets.Text;
>
> public class ActionCopy extends Action
> {
>
> private final static String ACTION_ID =
> "test.get.selection.copyAction"; //$NON-NLS-1$
>
> private Text text;
>
> public ActionCopy(Text text)
> {
> this.text = text;
> setId(ACTION_ID);
> }
>
> @Override
> public void run()
> {
> System.out.println(text.getSelectionText());
> }
>
> public void setEnabled()
> {
> setEnabled(text.getSelectionCount() > 0);
> }
>
> }
>
Re: Text.getSelectionText() [message #640705 is a reply to message #640697] Mon, 22 November 2010 21:21 Go to previous message
DANIEL  is currently offline DANIEL Friend
Messages: 13
Registered: November 2010
Junior Member
Opened Bug 330857
Previous Topic:Trying to use the PaperClips component
Next Topic:Request parameters problem in version 1.4 M3
Goto Forum:
  


Current Time: Thu Apr 25 13:08:41 GMT 2024

Powered by FUDForum. Page generated in 0.04372 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top