6 Replies Latest reply on Jan 2, 2012 1:51 AM by Anjum Shahzad Malik

    Detect right click on textinput and richeditabletext

    Godly_Dev

      I am currently using squiggle to perform spellchecking of a few TextInput and RichEditableText components. Unfortunately, due to certain requirements, I cannot use SpellUI, and must instead implement my own version.

      I have succeeded in getting spellCheck() to check and underline incorrectly spelt words. I am now trying to populate a list of suggested corrections into the context menu when someone right clicks on a word.

      I have attached an event listener to the richeditabletext's context menu, which is being fired everytime someone right clicks:

       

      richtexteditor.contextMenu.addeventListener(ContextMenuEvent.MENU_SELECT, showSuggestions);


      Here is my handler:

      private function showSuggestions(event:ContextMenuEvent):void{
      {

      }

      The problem is that I need to be able to know which word the mouse cursor was pointing over. I have tried using richtexteditor.selectionActivePosition, but this shows the position of the carat in the richeditabletext, and not the location of the mouse cursor.

      I need the behaviour to be like the one in squiggly's SpellUI: http://labs.adobe.com/technologies/squiggly/demo/#app=dba7&b322-selectedIndex=0

      How can I grab the location of the mouse cursor and determine which word it's pointing over?

        • 1. Re: Detect right click on textinput and richeditabletext
          vascopiff

          Hi,

          I have exactly the same issue, no idea how to find the position of the right click event.

          Godly_dev, did you find a solution for this?

          • 2. Re: Detect right click on textinput and richeditabletext
            Carol L. Frampton Level 2

            I'm not sure if there is a better way but I think this would work.

             

            I think you need to work with TextLines to map the mouse position to the word.

             

            To get at the TextLines from RichEditableText you can use the mx_internal getter textContainerManager.

             

                mx_internal function get textContainerManager():TextContainerManager

             

            And in the TextContaimer manager you can use these to get at the TextLines

             

            public function getLineAt(index:int):TextLine

             

            public function get numLines():int

             

            Once you have TextLines you can use TextLine.getAtomIndexAtPoint(stageX, stageY) to get at the word.

             

            Carol

             

            • 3. Re: Detect right click on textinput and richeditabletext
              vascopiff Level 1

               

              Thank you!! It's exactly the way I found to solve this issue. Not elegant at all but it works.

              I'm attaching a simple chunk of code that i did to make some test.

               

               

              This function finds the text index position of the mouse over the text.

              (this.lastY and this.lastX are the last position coordinates of mouse over the TextArea component)

               

              private function buildContextMenu(event:ContextMenuEvent):void{  

                 var textFlow:IFlowComposer = RichEditableText(this.textDisplay).textFlow.flowComposer;  

                 var textline:TextLine;

                 var textFlowLine:TextFlowLine;

                 var indexCount:int = 0;

                

                 for(var i:int; i<textFlow.numLines; i++){

                  textFlowLine = textFlow.getLineAt(i);

                  textline = textFlow.getLineAt(i).getTextLine(true);

                 

                  //trace("line("+i+"): "+textline.atomCount);

                  if(this.lastY > textFlowLine.getBounds().y && this.lastY < textFlowLine.getBounds().y + textFlowLine.getBounds().height){

                   for(var k:int; k<textline.atomCount; k++){

                    if(this.lastX > textline.getAtomBounds(k).x && this.lastX < textline.getAtomBounds(k).x + textline.getAtomBounds(k).width){

                     break;

                    }else{

                     indexCount++;

                    }

                   }

                   break;

                  }else{

                   indexCount+=textline.atomCount;

                  }

                 }

                

                 //trace("indexCount: "+indexCount);

              }

              • 4. Re: Detect right click on textinput and richeditabletext
                Anjum Shahzad Malik Level 1

                Can anybody please help me to underline/draw squiggly line below the missspelled words?

                • 5. Re: Detect right click on textinput and richeditabletext
                  Anjum Shahzad Malik Level 1

                  Hi Vacsopiff,

                   

                  your above code is not working in case of multiple line. if i have more than one line then its returing last atom index always.

                   

                  Can you guide me to resolve this issue please?

                  • 6. Re: Detect right click on textinput and richeditabletext
                    vascopiff Level 1

                    Hi, did you find out what's wrong with multiline? Actually, I'm using that code in a multiline controller too and I don't have problems, so I don't know how to guide you to solve the issue .... but if you find some bug please let us know!!!