-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add inputLength
to seek
and keyCount
to keypress
#308
base: master
Are you sure you want to change the base?
Changes from all commits
05bfdd8
23182a6
4f8b985
d2d5cee
6b07685
3ef52e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -466,9 +466,13 @@ export function notifyPromptActionRequested(action: "next" | "previous" | "clear | |||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Awaits a keypress from the user and returns the entered key. | ||||||||||||
* Awaits for one or more keypresses from the user and returns the entered keys. | ||||||||||||
* | ||||||||||||
* @param keyCount Determines the number of keypresses to wait for; defaults to 1. | ||||||||||||
*/ | ||||||||||||
export async function keypress(context = Context.current): Promise<string> { | ||||||||||||
export async function keypress(params: Readonly<{ keyCount?: number }>, | ||||||||||||
context = Context.current): Promise<string> { | ||||||||||||
const keyCount = params.keyCount || 1; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||||||||||||
if (context.cancellationToken.isCancellationRequested) { | ||||||||||||
return Promise.reject(new CancellationError(CancellationError.Reason.CancellationToken)); | ||||||||||||
} | ||||||||||||
|
@@ -479,12 +483,15 @@ export async function keypress(context = Context.current): Promise<string> { | |||||||||||
|
||||||||||||
return await new Promise<string>((resolve, reject) => { | ||||||||||||
try { | ||||||||||||
let keys = ""; | ||||||||||||
Comment on lines
485
to
+486
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I try to only put throwing stuff in
Suggested change
|
||||||||||||
const subscriptions = [ | ||||||||||||
vscode.commands.registerCommand("type", ({ text }: { text: string; }) => { | ||||||||||||
if (subscriptions.length > 0) { | ||||||||||||
keys += text; | ||||||||||||
if (subscriptions.length > 0 && keys.length >= keyCount) { | ||||||||||||
subscriptions.splice(0).forEach((s) => s.dispose()); | ||||||||||||
|
||||||||||||
context.switchToMode(previousMode).then(() => resolve(text)); | ||||||||||||
context.switchToMode(previousMode) | ||||||||||||
.then(() => resolve(keys.slice(0, keyCount))); | ||||||||||||
} | ||||||||||||
}), | ||||||||||||
|
||||||||||||
|
@@ -511,13 +518,13 @@ export async function keypress(context = Context.current): Promise<string> { | |||||||||||
* Awaits a keypress describing a register and returns the specified register. | ||||||||||||
*/ | ||||||||||||
export async function keypressForRegister(context = Context.current) { | ||||||||||||
const firstKey = await keypress(context); | ||||||||||||
const firstKey = await keypress({}, context); | ||||||||||||
|
||||||||||||
if (firstKey !== " ") { | ||||||||||||
return context.extension.registers.get(firstKey); | ||||||||||||
} | ||||||||||||
|
||||||||||||
const secondKey = await keypress(context); | ||||||||||||
const secondKey = await keypress({}, context); | ||||||||||||
|
||||||||||||
return context.extension.registers.forDocument(context.document).get(secondKey); | ||||||||||||
} | ||||||||||||
|
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 guessing this is a result of having an initial command and then removing it (the script that generates this file tries to keep old values to avoid throwing away manual changes). This should be removed (and ditto a bit lower in the file).