Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct text navigation in VB and C# strings #945

Merged
merged 1 commit into from
Mar 4, 2015

Conversation

brettfo
Copy link
Member

@brettfo brettfo commented Feb 27, 2015

Correct text navigation in VB and C# strings to match that of the old language service (i.e., VS 2013.) Now when navigating inside of strings with Ctrl+LeftArrow, RightArrow the cursor will move on word/token boundaries and Ctrl+Delete, Backspace behave appropriately as well as double-click word selection.

Fixes #551.

@brettfo
Copy link
Member Author

brettfo commented Feb 27, 2015

test this please

@brettfo
Copy link
Member Author

brettfo commented Feb 27, 2015

Tagging @Pilchie @DustinCampbell @rchande @dpoeschl @jasonmalinowski @balajikris @basoundr as potential reviewers.

Also, it looks like Jenkins messed itself trying to build. I'll keep trying periodically.

Dim Span = New Span(position.Position, 1)
Return New TextExtent(New SnapshotSpan(position.Snapshot, Span), isSignificant:=True)
Else
Return MyBase.GetExtentOfWordFromToken(token, position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this (and the stringliteraltoken case of IsWithinNaturalLanguage) are essentially the same in C# and VB, is there a way we can just push this up into the base type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since (C#)SyntaxKind.StringLiteralToken != (VB)SyntaxKind.StringLiteralToken I didn't see a clean way of doing this so I opted to keep them separate, but I could certainly be talked either way.

@rchande
Copy link
Contributor

rchande commented Feb 27, 2015

👍

return position > token.SpanStart;
// This, in combination with the override of GetExtentOfWordFromToken() below, treats the closing
// quote as a separate token. This maintains behavior with VS2013.
if (position == token.Span.End - 1 && token.Text.EndsWith("\""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, makes me want to have an overload of EndsWith that takes a char.

@brettfo brettfo force-pushed the vb-string-navigation branch from b987a4c to 00c79a7 Compare February 27, 2015 23:13
@jasonmalinowski
Copy link
Member

Important test here: make sure you can Ctrl+Left arrow and Ctrl+Right arrow back and forth across the file. I'm sure you've already done that, but you really want to make sure you don't break that...

@brettfo
Copy link
Member Author

brettfo commented Feb 28, 2015

@jasonmalinowski yep, that works. Truth be told I fiddled with it until I could navigate like I expected then I just made the tests pass to match.

@@ -254,7 +254,7 @@ public void String()
TestString,
pos: TestString.LastIndexOf('"'),
isSignificant: true,
start: startOfString + lengthOfStringIncludingQuotes - 1, length: 2);
start: startOfString + lengthOfStringIncludingQuotes - 1, length: 1);

AssertExtent(
TestString,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new tests for C#?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already had tests for C# interpolated strings that were correct; only regular/raw strings needed to be updated to treat the closing quote as a single token.

@Pilchie
Copy link
Member

Pilchie commented Mar 3, 2015

👍

return position > token.SpanStart;
// This, in combination with the override of GetExtentOfWordFromToken() below, treats the closing
// quote as a separate token. This maintains behavior with VS2013.
if (position == token.Span.End - 1 && token.Text.EndsWith("\"", StringComparison.Ordinal))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing with a single 'return'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried changing this to a single return statement but since the condition needed to be inverted it was difficult to read/understand, so for readability's sake I'm going to leave this.

@brettfo brettfo force-pushed the vb-string-navigation branch from 00c79a7 to c4a4da2 Compare March 4, 2015 02:03
brettfo added a commit that referenced this pull request Mar 4, 2015
correct text navigation in VB and C# strings
@brettfo brettfo merged commit d8d9a75 into dotnet:master Mar 4, 2015
@brettfo brettfo deleted the vb-string-navigation branch March 4, 2015 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Word selection doesn't work in VB string interpolation literals
8 participants