File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed
packages/core/src/prompts Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @clack/core " : patch
3+ ---
4+
5+ Fixes a rendering bug with cursor positions for ` TextPrompt `
Original file line number Diff line number Diff line change @@ -7,7 +7,17 @@ export interface TextOptions extends PromptOptions<TextPrompt> {
77}
88
99export default class TextPrompt extends Prompt {
10- valueWithCursor = '' ;
10+ get valueWithCursor ( ) {
11+ if ( this . state === 'submit' ) {
12+ return this . value ;
13+ }
14+ if ( this . cursor >= this . value . length ) {
15+ return `${ this . value } ${ color . inverse ( color . hidden ( '_' ) ) } ` ;
16+ }
17+ const s1 = this . value . slice ( 0 , this . cursor ) ;
18+ const [ s2 , ...s3 ] = this . value . slice ( this . cursor ) ;
19+ return `${ s1 } ${ color . inverse ( s2 ) } ${ s3 . join ( '' ) } ` ;
20+ }
1121 get cursor ( ) {
1222 return this . _cursor ;
1323 }
@@ -18,16 +28,6 @@ export default class TextPrompt extends Prompt {
1828 if ( ! this . value ) {
1929 this . value = opts . defaultValue ;
2030 }
21- this . valueWithCursor = this . value ;
22- } ) ;
23- this . on ( 'value' , ( ) => {
24- if ( this . cursor >= this . value . length ) {
25- this . valueWithCursor = `${ this . value } ${ color . inverse ( color . hidden ( '_' ) ) } ` ;
26- } else {
27- const s1 = this . value . slice ( 0 , this . cursor ) ;
28- const s2 = this . value . slice ( this . cursor ) ;
29- this . valueWithCursor = `${ s1 } ${ color . inverse ( s2 [ 0 ] ) } ${ s2 . slice ( 1 ) } ` ;
30- }
3131 } ) ;
3232 }
3333}
You can’t perform that action at this time.
0 commit comments