You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by David McNelis <Dm...@sharedmarketing.com> on 2010/05/05 16:00:02 UTC

TextArea v. TextInput - Selection and Autocomplete

Morning folks,

 

I have a set of information that I'm trying to auto-complete.  With a
TextInput I didn't have any problems setting the 'result' and then
highlighting the suggestion.  However, I am having trouble doing
something similar in a TextArea.

 

Specifically if I find a valid result the following snippet is called
for a TextInput:

 

                String text = textInput.getText();

                String resultString = getCompletedString(text);

                

textInput.setText(resultString);

 

int selectionStart = text.length();

int selectionLength = resultString.length() - selectionStart;

 

textInput.setSelection(selectionStart, selectionLength);

 

 

The auto-complete functions as I'd want it in the TextInput just fine.
But when I port it to a TextArea the selection isn't processed in the
same way.  I would just use a TextInput, however (and maybe I'm wrong),
TextInput can't span multiple lines and the amount of text that might
get tossed into the area is often too large to fit on a single line.
Also, I can't seem to set a specific index to set the cursor at in a
TextArea either...looking at the methods available there is a
TextArea.setCursor() method, but that doesn't take in an index at all.

 

Am I missing something simple?  Or am I trying to use a TextArea in a
way that I shouldn't be?

 

Thanks for your thoughts,

David


RE: TextArea v. TextInput - Selection and Autocomplete

Posted by David McNelis <Dm...@sharedmarketing.com>.
Thank you Noel and Greg.  It was the caret that I was trying to
place...and at the same time I was trying to highlight the remain text
that followed the caret position.

 

I've got the caret correctly moving now, which is a bonus.  But not so
much with the selection of the following text.  However its not much of
an issue for me at this point, as I opted to change that part of the
functionality to something a little more useful...

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Thursday, May 06, 2010 6:25 AM
To: user@pivot.apache.org
Subject: Re: TextArea v. TextInput - Selection and Autocomplete

 

The selection logic should work the same for TextArea as it does for
TextInput. Not sure what the problem might be.

 

Re: cursor - do you mean "cursor" or "caret"? Cursor generally refers to
the mouse pointer, whereas caret refers to the blinking line
representing the insertion point for text. setCursor() controls the
cursor style - calling setSelection() with a selection length of 0
positions the caret.

 

On May 5, 2010, at 10:00 AM, David McNelis wrote:





Morning folks,

 

I have a set of information that I'm trying to auto-complete.  With a
TextInput I didn't have any problems setting the 'result' and then
highlighting the suggestion.  However, I am having trouble doing
something similar in a TextArea.

 

Specifically if I find a valid result the following snippet is called
for a TextInput:

 

                String text = textInput.getText();

                String resultString = getCompletedString(text);

               

textInput.setText(resultString);

 

int selectionStart = text.length();

int selectionLength = resultString.length() - selectionStart;

 

textInput.setSelection(selectionStart, selectionLength);

 

 

The auto-complete functions as I'd want it in the TextInput just fine.
But when I port it to a TextArea the selection isn't processed in the
same way.  I would just use a TextInput, however (and maybe I'm wrong),
TextInput can't span multiple lines and the amount of text that might
get tossed into the area is often too large to fit on a single line.
Also, I can't seem to set a specific index to set the cursor at in a
TextArea either...looking at the methods available there is a
TextArea.setCursor() method, but that doesn't take in an index at all.

 

Am I missing something simple?  Or am I trying to use a TextArea in a
way that I shouldn't be?

 

Thanks for your thoughts,

David

 


Re: TextArea v. TextInput - Selection and Autocomplete

Posted by Greg Brown <gk...@mac.com>.
The selection logic should work the same for TextArea as it does for TextInput. Not sure what the problem might be.

Re: cursor - do you mean "cursor" or "caret"? Cursor generally refers to the mouse pointer, whereas caret refers to the blinking line representing the insertion point for text. setCursor() controls the cursor style - calling setSelection() with a selection length of 0 positions the caret.

On May 5, 2010, at 10:00 AM, David McNelis wrote:

> Morning folks,
>  
> I have a set of information that I’m trying to auto-complete.  With a TextInput I didn’t have any problems setting the ‘result’ and then highlighting the suggestion.  However, I am having trouble doing something similar in a TextArea.
>  
> Specifically if I find a valid result the following snippet is called for a TextInput:
>  
>                 String text = textInput.getText();
>                 String resultString = getCompletedString(text);
>                
> textInput.setText(resultString);
>  
> int selectionStart = text.length();
> int selectionLength = resultString.length() - selectionStart;
>  
> textInput.setSelection(selectionStart, selectionLength);
>  
>  
> The auto-complete functions as I’d want it in the TextInput just fine.  But when I port it to a TextArea the selection isn’t processed in the same way.  I would just use a TextInput, however (and maybe I’m wrong), TextInput can’t span multiple lines and the amount of text that might get tossed into the area is often too large to fit on a single line.  Also, I can’t seem to set a specific index to set the cursor at in a TextArea either…looking at the methods available there is a TextArea.setCursor() method, but that doesn’t take in an index at all.
>  
> Am I missing something simple?  Or am I trying to use a TextArea in a way that I shouldn’t be?
>  
> Thanks for your thoughts,
> David


Re: TextArea v. TextInput - Selection and Autocomplete

Posted by Noel Grandin <no...@gmail.com>.
Hi David

TextArea treats the start of the selection area as the caret point. So
you can set the caret location by doing
   setSelection(index, 0);

Do you have some test-case code? A stripped down sample would make it
easier to debug this.

Regards, Noel Grandin

David McNelis wrote:
>
> Morning folks,
>
>  
>
> I have a set of information that I'm trying to auto-complete.  With a
> TextInput I didn't have any problems setting the 'result' and then
> highlighting the suggestion.  However, I am having trouble doing
> something similar in a TextArea.
>
>  
>
> Specifically if I find a valid result the following snippet is called
> for a TextInput:
>
>  
>
>                 String text = textInput.getText();
>
>                 String resultString = getCompletedString(text);
>
>                
>
> textInput.setText(resultString);
>
>  
>
> *int* selectionStart = text.length();
>
> *int* selectionLength = resultString.length() - selectionStart;
>
>  
>
> textInput.setSelection(selectionStart, selectionLength);
>
>  
>
>  
>
> The auto-complete functions as I'd want it in the TextInput just
> fine.  But when I port it to a TextArea the selection isn't processed
> in the same way.  I would just use a TextInput, however (and maybe I'm
> wrong), TextInput can't span multiple lines and the amount of text
> that might get tossed into the area is often too large to fit on a
> single line.  Also, I can't seem to set a specific index to set the
> cursor at in a TextArea either...looking at the methods available
> there is a TextArea.setCursor() method, but that doesn't take in an
> index at all.
>
>  
>
> Am I missing something simple?  Or am I trying to use a TextArea in a
> way that I shouldn't be?
>
>  
>
> Thanks for your thoughts,
>
> David
>