-
-
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 increment and decrement operators #515
Conversation
} | ||
|
||
// Advance to the end of the word in case it's longer | ||
return Position.FromVSCodePosition(endPos.translate(0, newNum.length - oldWidth)); |
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.
Not sure about this, feels weird to create an intermediate object just to move a character. Thoughts?
46adb9d
to
faa43d3
Compare
This adds support for single or numeric-prefix control+x and control+a.
const text = TextEditor.getLineAt(position).text; | ||
|
||
// They may start on a number, so check the current word boundaries first. | ||
let wordEnd = position.getCurrentWordEnd(true); |
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 worried about relying on word boundaries as users are allowed to customize word separators, see #487 . Will this be a problem?
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.
Interesting, yes that could be a problem. Is there going to be a different API to get "builtin" word boundary matching? Should I just use a custom regex for this movement?
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 can't use getWord
as it always reads from user settings or default, I suppose want to want to get is something starts with numbers or +
and -
, a custom regex may do the trick.
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.
Looks like all of the current Position methods that take regexp's are private -- do you think I should change the visibility, or subclass Position
to something like NonCustomizablePosition
that does not respect user settings for word boundaries?
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.
If a user is insane enough to define numbers as word separators, these motions make no semantic sense (is 1234 4 separate words or one? If we select the whole thing with visual mode and do ctrl a, what should happen?)
I'm completely fine with this being undefined behavior.
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.
Sounds good to me.
Updated with a |
The only thing left that this PR does not implement (trying to understand how useful it is): given
hitting gives you
|
@sectioneight that seems of very little use. It doesn't make a lot of sense to guess how many bits are in the user's variable. 😛 |
@@ -179,7 +179,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
showCmdLine("", modeHandlerToEditorIdentity[new EditorIdentity(vscode.window.activeTextEditor).toString()]); | |||
}); | |||
|
|||
'rfbducw['.split('').forEach(key => { | |||
'rfbducw[ax'.split('').forEach(key => { |
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.
is there any specific ordering to the strings here? should we alphabetize them? reverse-alphabetize? put our favorite ones first?
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.
hah! there's no order, but yeah, this thing is pretty dumb. honestly i think we should parse them directly out of package.json and DRY this up, but that's a job for another day.
@@ -0,0 +1,36 @@ | |||
export class NumericString { |
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 think you could actually write this whole thing very concisely (less than 10 lines) with 3 separate regexes. Just do grouped matches to grab the values and then send them through parseInt. Something like this:
8: /^0([0-7]+),
10: /^(\d+)/,
16: /0x([\da-fA-F]+)/
}```
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.
Good call, updated with what I think you meant
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.
Yeah, LGTM, though maybe I slightly exaggerated how short it was going to be.
@@ -503,8 +503,6 @@ export class ModeHandler implements vscode.Disposable { | |||
} | |||
|
|||
async handleKeyEvent(key: string): Promise<Boolean> { | |||
if (key === "<c-r>") { key = "ctrl+r"; } // TODO - temporary hack for tests only! |
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.
Did someone fix this?
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 (let { start, end, word } of Position.IterateWords(position.getWordLeft(true))) { | ||
// '-' doesn't count as a word, but is important to include in parsing the number | ||
if (text[start.character - 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.
Use word
here rather than text, start and end.
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 can't, because I'm testing outside of the returned word (since -
isn't included in the word boundaries)
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.
Oh geez, that actually seems like it could have some bad interactions with people who DONT use - as a word delimiter. It's also really annoying. Oh well, it's fine for now.
Ok, sweet. Just remove the hack fix and we should be good to go. |
Remove which hack fix? I think I already undid the changes to tokenization. |
Yup, you're right, I must have been looking at an old version of the code. Sweet. LGTM! |
(Thanks for putting up with all my crazy requests! 😁 ) |
haha all good, I'm the same way on code reviews at work
|
This adds support for single or numeric-prefix control+x and control+a.
Numeric modes supported:
Fixes #513