Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:24:00+00:00 2026-06-10T14:24:00+00:00

I am trying to find a way to keep selected text highlighted when a

  • 0

I am trying to find a way to keep selected text highlighted when a user activates a context menu (right-click menu) using Sencha’s EXT GWT 2.x (though I’m fine with a 3.x solution if there is one).

The use case:

  1. User is viewing content on the screen.
  2. User selects some block of text (and phrase for example).
  3. User right-clicks to view the context menu so they may take action on the selected text and sees a context menu. The selected text remains selected when the menu appears.

In testing it appears that the GXT context menu automatically de-selects the text when the menu appears. Is there a way to prevent this and take action on the selected text?

So far I have tried:

a. Add a listener to the panel for the Context Menu event (Events.OnContextMenu) to see if there is a property that I can change (something like contextMenu.disableTextSelection(false) even though it was already set on construction of the view).

b. Overriding the de-select effect created by the appearance of the context menu by adding a native method to the same listener (Events.OnContextMenu) which then uses JS to try and grab the currently selected text, copy it to a temp variable, and then immediately add it back to the range on the page (effectively re-selecting the already selected text), but this didn’t work either. I was able to confirm that the native method fired, detected the text and appeared to drop it back into the range, but it seems that perhaps another event fires or some other action occurs which still clears the selection out before the menu appears.

Any ideas would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:24:01+00:00Added an answer on June 10, 2026 at 2:24 pm

    I’m still not aware of an official solution and I am starting to think this is a bug in GXT 2.x but I was able to come up with a workaround and am posting it here in case someone else should run into a similar problem.

    For starters, the issue appears to occur in Firefox and not in IE. For Firefox, the following worked (example code snippets after the summary):

    1. Add a listener to the Events.OnContextMenu event on your component/container/panel/etc.
      • Override the handleEvent method and add a native method to use JS to detect if the user has selected text on the screen. If text is selected, save it off to a JavaScriptObject (opaque wrapper of JS objects provided by GWT, see GWT documentation for details).
    2. Add a listener to the Events.Show event on the context menu object.
      • Override the handleEvent method and add a native method to use JS to re-select the previous selection.
    3. Add a listener to the Events.Hide event on the context menu object.
      • Override the handleEvent method and clear our your selection variable and then run a native method to clear out any remaining selection (if desired).

    Using these steps I was able to keep the text selected when making a context menu appear in Firefox.

    Example Code
    (these are just sample code blocks to help better illustrate the steps – a copy/paste of this code won’t give you everything you need)

    public class ContextMenuExample {
    
        JavaScriptObject selection;
        Menu contextMenu = new Menu();
    
      public void buildPanelExample() {
    
        ContentPanel panel = new ContentPanel();  
        panel.addListener(Events.onContextMenu, new Listener<BaseEvent>() {
          if (!GXT.isIE) {
            selection = findSelectedTextOnScreen();
          }
        });
    
        contextMenu.addListener(Events.Show, new Listener<BaseEvent>() {
          if (!GXT.isIE) {
            reSelectText(selection);
          }
        });
    
        contextMenu.addListener(Events.Hide, new Listener<BaseEvent>() {
          if (!GXT.isIE) {
            clearSelection();
          }
        });
    
        private native JavaScriptObject findSelectedTextOnScreen() /*-{
          // use JS method to get selected text as a range
          return selectedText;
        }-*/;
    
        private native void reSelectedText(JavaScriptObject range) /*-{
          // use JS method to find a range a select it
        }-*/;
    
        private native void clearSelection() /*-{ 
          // us JS to clear any selected ranges 
        }-*/;
    
        private void clearSelections() {
          selection = null;
          clearSelection();
        }
    
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a way to terminate a loop when the user hits
I'm trying to find the best way to keep my clients updated as fast
I am designing my website and I'm trying to find a way to keep
I am trying to find a way to get the source code for (user
I'm trying to find a way to keep track of files even when they
I am trying to find a way to keep connected with the Twitter API
I am trying to find a way to keep connected with the Facebook API
I am trying to find what the easiest way to keep form values after
I keep trying to find a way to associate data with users in authlogic.
Trying to find a way to remove blank pages from a document I wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.