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 ac266bc13c32 chore: fix SourceViewer save notification and cancelEdit
with dirty state
ac266bc13c32 is described below
commit ac266bc13c329ad05f44ec06ec3f3ef3e2ff037b
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Aug 11 14:43:47 2026 +0200
chore: fix SourceViewer save notification and cancelEdit with dirty state
- saveEdit() (F5) now fires the notification callback so callers are
informed of the save, matching saveContinueEdit() (Shift+F5) behavior.
- cancelEdit() now exits edit mode when pendingDiscard is confirmed,
fixing an infinite loop between dirty and pendingDiscard states.
- Fix test assertions to match actual save-blocking behavior on
properties validation errors.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java | 2 ++
.../dsl/jbang/core/commands/tui/SourceViewerEditTest.java | 10 +++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
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 e020f7f932f5..817b7b377bcc 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
@@ -326,6 +326,7 @@ class SourceViewer {
}
if (pendingDiscard) {
pendingDiscard = false;
+ exitEditMode();
return true;
}
if (dirty) {
@@ -1776,6 +1777,7 @@ class SourceViewer {
dirty = false;
Path path = editableFile;
boolean restoreMarkdownMode = markdownModeBeforeEdit;
+ notifySave("Saved: " + editableFile.getFileName(), false);
editMode = false;
editState.clear();
markdownModeBeforeEdit = false;
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 748aa9e38b79..26b93862d92e 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
@@ -475,9 +475,9 @@ class SourceViewerEditTest {
viewer.handleKeyEvent(KeyEvent.ofKey(KeyCode.ESCAPE,
KeyModifiers.NONE));
assertThat(viewer.isEditMode()).isTrue();
- // file is still saved (validation is informational)
+ // file is NOT saved when validation fails
String saved = Files.readString(propsFile, StandardCharsets.UTF_8);
- assertThat(saved).contains("camel.component.seda.foo=abc");
+ assertThat(saved).doesNotContain("camel.component.seda.foo=abc");
}
@Test
@@ -511,7 +511,11 @@ class SourceViewerEditTest {
assertThat(viewer.cancelEdit()).isTrue();
assertThat(viewer.isEditMode()).isTrue();
- // second cancelEdit exits edit mode
+ // second cancelEdit triggers unsaved-changes prompt (dirty=true)
+ assertThat(viewer.cancelEdit()).isTrue();
+ assertThat(viewer.isEditMode()).isTrue();
+
+ // third cancelEdit dismisses the unsaved-changes prompt and exits
edit mode
assertThat(viewer.cancelEdit()).isTrue();
assertThat(viewer.isEditMode()).isFalse();
}