This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new fb4f0aa49da4 camel-tui - Confirm before discarding unsaved changes on 
Esc in edit mode
fb4f0aa49da4 is described below

commit fb4f0aa49da4024ac192a5abd4ef9355a398da41
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Aug 6 06:48:41 2026 +0200

    camel-tui - Confirm before discarding unsaved changes on Esc in edit mode
    
    When the editor has unsaved changes (dirty flag), pressing Esc now shows
    a warning notification instead of immediately exiting. Press Esc again to
    confirm discard, or any other key to continue editing. If there are no
    changes, Esc exits immediately as before.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../dsl/jbang/core/commands/tui/SourceViewer.java   | 21 +++++++++++++++++++++
 .../core/commands/tui/SourceViewerEditTest.java     |  3 +++
 2 files changed, 24 insertions(+)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
index 1c0d7a60326e..9ec634423ae6 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
@@ -140,6 +140,7 @@ class SourceViewer {
     /** Markdown render mode prior to entering edit; restored on cancel. */
     private boolean markdownModeBeforeEdit;
     private boolean dirty;
+    private boolean pendingDiscard;
     private BiConsumer<String, Boolean> notificationCallback;
     private AutocompletePopup.AutocompleteProvider autocompleteProvider;
     private AutocompletePopup.ValueProvider autocompleteValueProvider;
@@ -279,6 +280,14 @@ class SourceViewer {
             autocompletePopup = null;
             return true;
         }
+        if (dirty && !pendingDiscard) {
+            pendingDiscard = true;
+            if (notificationCallback != null) {
+                notificationCallback.accept("Unsaved changes will be lost — 
press Esc again to discard", true);
+            }
+            return true;
+        }
+        pendingDiscard = false;
         exitEditMode();
         return true;
     }
@@ -468,7 +477,18 @@ class SourceViewer {
             }
             return true;
         }
+        if (!ke.isCancel()) {
+            pendingDiscard = false;
+        }
         if (ke.isCancel()) {
+            if (dirty && !pendingDiscard) {
+                pendingDiscard = true;
+                if (notificationCallback != null) {
+                    notificationCallback.accept("Unsaved changes will be lost 
— press Esc again to discard", true);
+                }
+                return true;
+            }
+            pendingDiscard = false;
             exitEditMode();
             return true;
         }
@@ -577,6 +597,7 @@ class SourceViewer {
         editState.clear();
         autocompletePopup = null;
         validationErrors = null;
+        pendingDiscard = false;
         if (wasEditing && isMarkdownFile) {
             markdownMode = markdownModeBeforeEdit;
         }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewerEditTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewerEditTest.java
index e4b9c4d01808..a70e9610fab2 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewerEditTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewerEditTest.java
@@ -150,6 +150,9 @@ class SourceViewerEditTest {
         for (char ch : "CHANGED".toCharArray()) {
             viewer.handleKeyEvent(KeyEvent.ofChar(ch, KeyModifiers.NONE));
         }
+        // first Esc shows discard warning, second Esc confirms
+        viewer.handleKeyEvent(KeyEvent.ofKey(KeyCode.ESCAPE, 
KeyModifiers.NONE));
+        assertThat(viewer.isEditMode()).isTrue();
         viewer.handleKeyEvent(KeyEvent.ofKey(KeyCode.ESCAPE, 
KeyModifiers.NONE));
 
         assertThat(viewer.isEditMode()).isFalse();

Reply via email to