Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Odd double clicking ?
Odd double clicking ? [message #908629] Wed, 05 September 2012 17:19 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I have noticed odd behaviour when double clicking to select text.
Somethimes only a single letter, sometimes two are selected, and
sometimes the entire word is correctly selected.

It seems related to where in the "word" the pointer is when double
clicking - if towards the beginning or end, it does the right thing, but
if in the middle it seems to prefer selecting a single or two characters.

My question is if Xtext is involved in this at all, and if so, any hints
where I should look for where this happens. I Can imagine that it
relates to what is being clicked on, and find the significant portion to
select.

Regards
- henrik
Re: Odd double clicking ? [message #908905 is a reply to message #908629] Thu, 06 September 2012 07:57 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Yes, Xtext handles this according to the lexer tokens with some special
semantics for ML comments and Strings.
See org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider
and
org.eclipse.xtext.ui.editor.doubleClicking.LexerTokenAndCharacterPairAwareStrategy

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 05.09.12 19:19, schrieb Henrik Lindberg:
> Hi,
> I have noticed odd behaviour when double clicking to select text.
> Somethimes only a single letter, sometimes two are selected, and
> sometimes the entire word is correctly selected.
>
> It seems related to where in the "word" the pointer is when double
> clicking - if towards the beginning or end, it does the right thing, but
> if in the middle it seems to prefer selecting a single or two characters.
>
> My question is if Xtext is involved in this at all, and if so, any hints
> where I should look for where this happens. I Can imagine that it
> relates to what is being clicked on, and find the significant portion to
> select.
>
> Regards
> - henrik
Re: Odd double clicking ? [message #908997 is a reply to message #908905] Thu, 06 September 2012 11:24 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-06-09 9:57, Sebastian Zarnekow wrote:
> Yes, Xtext handles this according to the lexer tokens with some special
> semantics for ML comments and Strings.
> See org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider
> and
> org.eclipse.xtext.ui.editor.doubleClicking.LexerTokenAndCharacterPairAwareStrategy
>

I debugged this, and found that DocumentParitioner is basing its
decision on faulty information.

Clicking at the position marked | in the string 'a|bcd', returns a
partition consisting of abcd only. It returns a region based on that.
The end result is a selection if bc only.

If I double click (marked |) 'ab|cd', I also get a region consisting of
abcd, but now I get the correct selection; all of abcd.

So - mapping to typed region seems ok.
In
o.e.xtext.ui.editor.doubleClicking.AbstractPartitionDoubleClickSelector.findExtendedDoubleClickSelection(IDocument,
int offset) however, it does this:

if (offset == region.getOffset() + 1
|| offset == region.getOffset() + region.getLength() - 1) {
return getSelectedRegion(document, region);
}
otherwise, it returns null. This is called for the
FixedCharCountPartitionDoubleClickSelector configured for the STRING
partition. (It in turn has margins of 1 assigned).

This seems to be the logic for "select the entire string if at one of
the ends", because if it returns null, the logic above continues with a
search for a Word match.

Everything would be ok, if the underlying region had included the
quotes. I do have a specialized implementation of
TokenTypeToStringMapper that includes these rules:

if("RULE_WORD_CHARS".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("RULE_ANY_OTHER".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'::'".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'$'".equals(tokenName))
return STRING_LITERAL_PARTITION;
// issue #276, screws up bracket matching
// if("'${'".equals(tokenName))
// return STRING_LITERAL_PARTITION;
if("'\\''".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\\\"'".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\\$'".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\\${'".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\\\\".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\''".equals(tokenName))
return STRING_LITERAL_PARTITION;
if("'\"'".equals(tokenName))
return STRING_LITERAL_PARTITION;

I have this binding:
public Class<? extends ITokenTypeToPartitionTypeMapper>
bindITokenTypeToPartitionTypeMapper() {
return PPTokenTypeToPartionMapper.class;
}

And I can see it gets called.

Is there another token to partition mapper involved?

Regards
- henrik
Re: Odd double clicking ? [message #909050 is a reply to message #908997] Thu, 06 September 2012 13:06 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Thanks to Sebastian Zarnekow, I now know that I needed to bind a
PartitionTokenScanner that does this:

protected boolean shouldMergePartitions(String contentType) {
return super.shouldMergePartitions(contentType) ||
PPTokenTypeToPartionMapper.STRING_LITERAL_PARTITION.equals(contentType);

Since it did not expect strings to be implemented with multiple tokens.

Now it works!

Regards
- henrik

On 2012-06-09 13:24, Henrik Lindberg wrote:
> On 2012-06-09 9:57, Sebastian Zarnekow wrote:
>> Yes, Xtext handles this according to the lexer tokens with some special
>> semantics for ML comments and Strings.
>> See
>> org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider
>> and
>> org.eclipse.xtext.ui.editor.doubleClicking.LexerTokenAndCharacterPairAwareStrategy
>>
>>
>
> I debugged this, and found that DocumentParitioner is basing its
> decision on faulty information.
>
> Clicking at the position marked | in the string 'a|bcd', returns a
> partition consisting of abcd only. It returns a region based on that.
> The end result is a selection if bc only.
>
> If I double click (marked |) 'ab|cd', I also get a region consisting of
> abcd, but now I get the correct selection; all of abcd.
>
> So - mapping to typed region seems ok.
> In
> o.e.xtext.ui.editor.doubleClicking.AbstractPartitionDoubleClickSelector.findExtendedDoubleClickSelection(IDocument,
> int offset) however, it does this:
>
> if (offset == region.getOffset() + 1
> || offset == region.getOffset() + region.getLength() - 1) {
> return getSelectedRegion(document, region);
> }
> otherwise, it returns null. This is called for the
> FixedCharCountPartitionDoubleClickSelector configured for the STRING
> partition. (It in turn has margins of 1 assigned).
>
> This seems to be the logic for "select the entire string if at one of
> the ends", because if it returns null, the logic above continues with a
> search for a Word match.
>
> Everything would be ok, if the underlying region had included the
> quotes. I do have a specialized implementation of
> TokenTypeToStringMapper that includes these rules:
>
> if("RULE_WORD_CHARS".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("RULE_ANY_OTHER".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'::'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'$'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> // issue #276, screws up bracket matching
> // if("'${'".equals(tokenName))
> // return STRING_LITERAL_PARTITION;
> if("'\\''".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\\\"'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\\$'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\\${'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\\\\".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\''".equals(tokenName))
> return STRING_LITERAL_PARTITION;
> if("'\"'".equals(tokenName))
> return STRING_LITERAL_PARTITION;
>
> I have this binding:
> public Class<? extends ITokenTypeToPartitionTypeMapper>
> bindITokenTypeToPartitionTypeMapper() {
> return PPTokenTypeToPartionMapper.class;
> }
>
> And I can see it gets called.
>
> Is there another token to partition mapper involved?
>
> Regards
> - henrik
>
>
>
>
>
Previous Topic:Inject issue with Eclipse Juno
Next Topic:Accessing the resource set from other plugin
Goto Forum:
  


Current Time: Fri Dec 04 03:13:55 GMT 2020

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

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

Back to the top