-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement quoted text objects #483
Conversation
|
||
// Didn't find one behind us, the string may start ahead of us | ||
for (let i = start; i < corpus.length; i++) { | ||
const currentChar = corpus[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a bit bad (but not too bad) about copy-pasting the body of these loops. Really what I want is to have some thing that takes an iterator and returns Either<position **or** notfound>
and then pass that iterator to the loops. But, I'm a total TypeScript noob and I didn't see an obvious way to do it.
87e493b
to
28f1c29
Compare
// Didn't find one behind us, the string may start ahead of us | ||
for (let i = start; i < corpus.length; i++) { | ||
const currentChar = corpus[i]; | ||
if (currentChar === char && corpus[i - 1] !== this.escapeChar) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried about the escape char, this can't handle \\"
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that is a limitation.
I looked at the algorithm used by other vim emulation stacks and this seemed to be the best one. I think we could handle that case by having another look-behind for another escape character? Or are there other pathological cases we'd still be missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have handled escape char while parsing subsitute commands https://github.com/VSCodeVim/Vim/blob/master/src/cmd_line/subparsers/substitute.ts . The logic is reading char one by one and handling every \
. I suppose we can do the same thing here?
For now I don't see any other case but I'll investigate.
Everything looks good to me except the |
5666361
to
977e7b5
Compare
@rebornix updated with handling of escaped backslashes |
@sectioneight I'm really sorry that I didn't think carefully about the escaping before I made suggestions. Checking double
but it's not a true closing |
Ah, right, of course it's not that easy :) What do you guys think? Should we parse the whole line or stick with the
|
I have a dirty but quick way to handle this, while iterating the text, skip all escaped chars then check whether it's a
I didn't handle corner cases carefully but I think you can get the idea. Besides, I don't have a strong opinion about postpoing the escaping handling or not, if we don't have a perfect solution right now, we can fix it later. It's up to you and @johnfn . |
OK, just pushed a new commit that pre-parses the line and handles your edge case properly. I'm not sure about performance implications, however -- is that something to be concerned about, or is that prematurely optimizing? |
3dca2b8
to
911109c
Compare
This one is ready to go |
constructor(char: string, corpus: string, start: number) { | ||
this.char = char; | ||
this.start = start; | ||
this.corpus = corpus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems this.corpus
is never used?
only have some tiny suggestions. The logic and code look good to me so I'm willing to see it merged. |
@rebornix great feedback, updated. |
}; | ||
} | ||
return { | ||
start: new Position(position.line, start + (this.includeSurrounding ? 0 : 1)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use position objects and getRight()/getLeft() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure.
The one big thing that we're missing here is
You currently select the inner " two " rather than the "three" to the right. I'm pretty sure that Vim actually determines which of the two potential quote sections is inside the quotes rather than outside and selects that one. Could you add in that case? This should be good to merge with that. |
Sounds good. Master tests are currently broken, I'm going to wait until that's resolved to push anything else here. |
6b21500
to
4497465
Compare
4497465
to
c78e07e
Compare
@johnfn updated. Note that there are test cases that currently fail, as master is currently red. |
Perfect! Thanks for the awesome work, @sectioneight! |
Fixes #471, #287