File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
main/java/com/flowingcode/vaadin/addons/xterm
test/java/com/flowingcode/vaadin/addons/xterm/integration Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ public class TerminalHistory implements Serializable {
3232
3333 private String lastRet ;
3434
35+ private String initialLine ;
36+
3537 private Integer maxSize ;
3638
3739 protected <T extends XTermBase & ITerminalConsole > TerminalHistory (T terminal ) {
@@ -93,7 +95,14 @@ public boolean isEnabled() {
9395 }
9496
9597 private void handleArrowUp () {
96- write (previous ());
98+ if (initialLine == null ) {
99+ ((ITerminalConsole ) terminal ).getCurrentLine ().thenAccept (currentLine -> {
100+ initialLine = currentLine ;
101+ write (previous ());
102+ });
103+ } else {
104+ write (previous ());
105+ }
97106 }
98107
99108 private void handleArrowDown () {
@@ -161,6 +170,7 @@ public void add(String line) {
161170
162171 private void setCurrentLine (String currentLine ) {
163172 if (!currentLine .equals (lastRet )) {
173+ initialLine = currentLine ;
164174 prefix = currentLine ;
165175 iterator = null ;
166176 }
@@ -181,7 +191,11 @@ private String previous() {
181191 }
182192
183193 private String next () {
184- return find (forwardIterator (), line -> true ).orElse ("" );
194+ return find (forwardIterator (), line -> true ).orElseGet (() -> {
195+ String result = initialLine ;
196+ initialLine = null ;
197+ return result ;
198+ });
185199 }
186200
187201 private String findPrevious (String currentLine ) {
Original file line number Diff line number Diff line change @@ -40,6 +40,27 @@ public void testArrowKeys() {
4040 assertThat (currentLine (term ), isEmptyString ());
4141 }
4242
43+ @ Test
44+ public void testArrowKeysAndRestore () {
45+ TestBenchElement term = $ ("fc-xterm" ).first ();
46+
47+ WebElement input = (WebElement ) waitUntil (driver -> ((HasTestBenchCommandExecutor ) driver )
48+ .getCommandExecutor ().executeScript ("return arguments[0].terminal.textarea" , term ));
49+
50+ int y = cursorPosition (term ).y ;
51+ input .sendKeys ("foo1\n foo2\n " );
52+
53+ assertThat (cursorPosition (term ), is (at (0 , y += 2 )));
54+ assertThat (lineAtOffset (term , 0 ), isEmptyString ());
55+
56+ input .sendKeys ("bar" );
57+ input .sendKeys (Keys .ARROW_UP );
58+ assertThat (currentLine (term ), is ("foo2" ));
59+
60+ input .sendKeys (Keys .ARROW_DOWN );
61+ assertThat (currentLine (term ), is ("bar" ));
62+ }
63+
4364 @ Test
4465 public void testPageUpDown () {
4566 TestBenchElement term = $ ("fc-xterm" ).first ();
You can’t perform that action at this time.
0 commit comments