File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -164,11 +164,15 @@ public function setInput($input)
164164 return $ this ;
165165 }
166166
167+ // remember old input length if echo replacement is used
168+ $ oldlen = (is_string ($ this ->echo )) ? $ this ->strlen ($ this ->linebuffer ) : null ;
169+
167170 $ this ->linebuffer = $ input ;
168171 $ this ->linepos = $ this ->strlen ($ this ->linebuffer );
169172
170173 // only redraw if input should be echo'ed (i.e. is not hidden anyway)
171- if ($ this ->echo !== false ) {
174+ // and echo replacement is used, make sure the input length changes
175+ if ($ this ->echo !== false && $ this ->linepos !== $ oldlen ) {
172176 $ this ->redraw ();
173177 }
174178
Original file line number Diff line number Diff line change @@ -124,6 +124,16 @@ public function testSettingInputWithEchoAsteriskDoesRedraw()
124124 $ this ->assertSame ($ this ->readline , $ this ->readline ->setInput ('test ' ));
125125 }
126126
127+ public function testSettingInputWithSameLengthWithEchoAsteriskDoesNotNeedToRedraw ()
128+ {
129+ $ this ->readline ->setInput ('test ' );
130+ $ this ->readline ->setEcho ('* ' );
131+
132+ $ this ->output ->expects ($ this ->never ())->method ('write ' );
133+
134+ $ this ->assertSame ($ this ->readline , $ this ->readline ->setInput ('demo ' ));
135+ }
136+
127137 public function testSettingInputWithoutEchoDoesNotNeedToRedraw ()
128138 {
129139 $ this ->readline ->setEcho (false );
You can’t perform that action at this time.
0 commit comments