Skip to content

Commit

Permalink
fix(prompt): pasting clipboard into prompt returns corrupted data (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Aug 1, 2020
1 parent f153909 commit 5de866c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/prompt/lib/generic-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ export abstract class GenericPrompt<T, V, S extends GenericPromptSettings<T, V>>
return this.validateValue( value );
}

const event: KeyEvent | undefined = await readKeySync();
const events: KeyEvent[] = await readKeySync();

if ( !event ) {
if ( !events.length ) {
return false;
}

const done: boolean = await this.handleEvent( event );
let done: boolean = false;

for ( const event of events ) {
done = await this.handleEvent( event );
}

if ( done ) {
return this.validateValue( this.getValue() );
Expand Down
8 changes: 4 additions & 4 deletions packages/prompt/lib/read-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export async function readCharSync(): Promise<Uint8Array | undefined> {

const buffer = new Uint8Array( 8 );

Deno.setRaw( 0, true );
Deno.setRaw( Deno.stdin.rid, true );
const nread: number | null = await Deno.stdin.read( buffer );
Deno.setRaw( 0, false );
Deno.setRaw( Deno.stdin.rid, false );

if ( nread === null ) {
return;
Expand All @@ -22,9 +22,9 @@ export async function readCharSync(): Promise<Uint8Array | undefined> {
return buffer.subarray( 0, nread );
}

export async function readKeySync(): Promise<KeyEvent | undefined> {
export async function readKeySync(): Promise<KeyEvent[]> {

const data = await readCharSync();

return data && KeyCode.parse( data );
return data ? KeyCode.parse( data ) : [];
}

0 comments on commit 5de866c

Please sign in to comment.