@@ -576,6 +576,7 @@ public InputResult execute() {
576576 List <Candidate > matches = new ArrayList <>();
577577 KeyMap <Operation > keyMap = new KeyMap <>();
578578 bindKeys (keyMap );
579+ StringBuilder displayBuffer = new StringBuilder ();
579580 StringBuilder buffer = new StringBuilder ();
580581 CompletionMatcher completionMatcher = new CompletionMatcherImpl ();
581582 boolean tabCompletion = completer != null && reader != null ;
@@ -596,7 +597,7 @@ public InputResult execute() {
596597 refreshDisplay (
597598 firstItemRow - 1 ,
598599 column ,
599- buffer .toString (),
600+ displayBuffer .toString (),
600601 row ,
601602 startColumn ,
602603 displayCandidates ? matches : new ArrayList <>());
@@ -608,48 +609,67 @@ public InputResult execute() {
608609 }
609610 break ;
610611 case RIGHT :
611- if (column < startColumn + buffer .length ()) {
612+ if (column < startColumn + displayBuffer .length ()) {
612613 column ++;
613614 }
614615 break ;
615616 case INSERT :
616- buffer .insert (column - startColumn , mask == null ? bindingReader .getLastBinding () : mask );
617+ displayBuffer .insert (
618+ column - startColumn , mask == null ? bindingReader .getLastBinding () : mask );
619+ buffer .insert (column - startColumn , bindingReader .getLastBinding ());
617620 column ++;
618621 break ;
619622 case BACKSPACE :
620623 if (column > startColumn ) {
624+ displayBuffer .deleteCharAt (column - startColumn - 1 );
621625 buffer .deleteCharAt (column - startColumn - 1 );
622626 column --;
623627 }
624628 break ;
625629 case DELETE :
626- if (column < startColumn + buffer .length () && column >= startColumn ) {
630+ if (column < startColumn + displayBuffer .length () && column >= startColumn ) {
631+ displayBuffer .deleteCharAt (column - startColumn );
627632 buffer .deleteCharAt (column - startColumn );
628633 }
629634 break ;
630635 case BEGINNING_OF_LINE :
631636 column = startColumn ;
632637 break ;
633638 case END_OF_LINE :
634- column = startColumn + buffer .length ();
639+ column = startColumn + displayBuffer .length ();
635640 break ;
636641 case SELECT_CANDIDATE :
637642 if (tabCompletion && matches .size () < ReaderUtils .getInt (reader , LineReader .LIST_MAX , 50 )) {
638643 String selected =
639644 selectCandidate (firstItemRow - 1 , buffer .toString (), row + 1 , startColumn , matches );
640645 resetHeader ();
641646 if (selected != null ) {
642- buffer .delete (0 , buffer .length ());
647+ displayBuffer .delete (0 , displayBuffer .length ());
648+ if (mask == null ) {
649+ displayBuffer .append (selected );
650+ } else {
651+ for (int i = 0 ; i < selected .length (); i ++) {
652+ displayBuffer .append (mask );
653+ }
654+ }
655+ buffer .delete (0 , displayBuffer .length ());
643656 buffer .append (selected );
644- column = startColumn + buffer .length ();
657+ column = startColumn + displayBuffer .length ();
645658 }
646659 }
647660 break ;
648661 case EXIT :
649- if (buffer .toString ().isEmpty ()) {
662+ if (displayBuffer .toString ().isEmpty ()) {
663+ if (mask == null ) {
664+ displayBuffer .append (defaultValue );
665+ } else {
666+ for (int i = 0 ; i < defaultValue .length (); i ++) {
667+ displayBuffer .append (mask );
668+ }
669+ }
650670 buffer .append (defaultValue );
651671 }
652- return new InputResult (buffer .toString ());
672+ return new InputResult (buffer .toString (), displayBuffer . toString () );
653673 case CANCEL :
654674 return null ;
655675 }
0 commit comments