Skip to content

Commit

Permalink
Option to disable Undo in LineReader
Browse files Browse the repository at this point in the history
Co-authored-by: datta.sid@gmail.com <datta.sid@example.com>
  • Loading branch information
dattasid and datta.sid@gmail.com committed Feb 15, 2022
1 parent 0bb26e9 commit f9b267f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ enum Option {

/** Show command options tab completion candidates for zero length word */
EMPTY_WORD_OPTIONS(true),

/** Disable the undo feature */
DISABLE_UNDO
;

private final boolean def;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ public String readLine(String prompt, String rightPrompt, MaskingCallback maskin

callWidget(CALLBACK_INIT);

undo.newState(buf.copy());
if (!isSet(Option.DISABLE_UNDO))
undo.newState(buf.copy());

// Draw initial prompt
redrawLine();
Expand Down Expand Up @@ -679,7 +680,7 @@ public String readLine(String prompt, String rightPrompt, MaskingCallback maskin
if (!w.apply()) {
beep();
}
if (!isUndo && copy != null && buf.length() <= getInt(FEATURES_MAX_BUFFER_SIZE, DEFAULT_FEATURES_MAX_BUFFER_SIZE)
if (!isSet(Option.DISABLE_UNDO) && !isUndo && copy != null && buf.length() <= getInt(FEATURES_MAX_BUFFER_SIZE, DEFAULT_FEATURES_MAX_BUFFER_SIZE)
&& !copy.toString().equals(buf.toString())) {
undo.newState(buf.copy());
}
Expand Down

0 comments on commit f9b267f

Please sign in to comment.