Skip to content

CAMEL-24287: Add plain text edit mode to TUI source viewer - #25204

Open
atiaomar1978-hub wants to merge 4 commits into
apache:mainfrom
atiaomar1978-hub:cursor/camel-24287-source-viewer-edit-26c6
Open

CAMEL-24287: Add plain text edit mode to TUI source viewer#25204
atiaomar1978-hub wants to merge 4 commits into
apache:mainfrom
atiaomar1978-hub:cursor/camel-24287-source-viewer-edit-26c6

Conversation

@atiaomar1978-hub

@atiaomar1978-hub atiaomar1978-hub commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a plain-text edit mode to the Camel JBang TUI source viewer for quick prototyping of local files (YAML routes, application.properties, Java, etc.) without leaving the terminal.

Behavior

  • Press e in the source viewer to enter edit mode (only when the loaded file is a local writable path from loadFile)
  • Press Esc to cancel and return to read-only view (syntax highlighting restored; markdown mode restored for .md files)
  • Press F5 to save; Camel dev mode then auto-reloads the changed file
  • Edit mode uses TamboUI TextArea with line numbers and no syntax highlighting
  • Tab does not steal focus while editing
  • Process-sourced views (loadSource / remote attach) remain read-only
  • Global digit/letter shortcuts are suppressed while editing; paste inserts into the editor

Tests

  • SourceViewerEditTest (20 tests): enter/cancel/save, Esc discard, paste, read-only, markdown restore, footer hints, save-message clearing, Tab swallowed in edit mode

JIRA: https://issues.apache.org/jira/browse/CAMEL-24287

AI-generated by Cursor Agent on behalf of Omar Atie

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run formatting (formatter:format / impsort:sort) and tests for the touched module.

AI-assisted contributions

  • If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., Co-authored-by trailers) and the PR description identifies the AI tool used.

@atiaomar1978-hub atiaomar1978-hub changed the title Cursor/camel 24287 source viewer edit 26c6 CAMEL-24287: Add plain text edit mode to TUI source viewer Jul 29, 2026
@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Review follow-up (Grok + Bugbot)

Independent Grok review of the diff was run; Bugbot was also requested.

Grok findings addressed in 86432a1

Severity Issue Fix
Critical Esc left the Source tab instead of canceling edit (CamelMonitor routes Esc to handleEscape before tab keys) SourceTab.handleEscape() now calls sourceViewer.cancelEdit() and returns true
Major Tab toggled focus mid-edit → silent discard risk Tab is swallowed while isEditMode()
Major Canceling edit on .md left markdown render off Remember/restore markdownModeBeforeEdit
Minor Stale “Saved” message after opening another file Clear saveMessage in loadFile

Extra tests added for markdown restore, cancel API, and Tab-while-editing.

Remaining (accepted / follow-up)

  • Line-ending normalization (readAllLines\n) — acceptable for v1 prototyping editor
  • Soft size/binary guard — future ticket
  • Unused isSourceViewerEditMode / paste-active alias cleanup — can tidy in a follow-up

bugbot run

AI-generated by Cursor Agent on behalf of Omar Atie

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

AI-generated comment on behalf of atiaomar1978-hub

Follow-up commit (9c2782d5f43) addresses Bugbot findings:

  • SourceTab: while the source viewer is in edit mode, keyboard events are routed to the viewer even when focus is on the file list (e.g. after clicking the left panel), so typing and F5 save still work.
  • SourceViewer.saveEdit(): after save/reload, markdown preview mode is restored to what the user had before edit (e.g. raw view after Space toggle), matching cancel behavior.

Tests: SourceViewerEditTest (22 tests), including savePreservesRawMarkdownViewAfterEdit and sourceTabForwardsKeysToViewerWhileEditing.

@github-actions github-actions Bot added the dsl label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-plugin-tui

🔬 Scalpel shadow comparison — Scalpel: 2 tested, 1 compile-only — current: 2 all tested

Maveniverse Scalpel detected 3 affected modules (current approach: 2).

⚠️ Modules only in Scalpel (1)
  • camel-launcher

Skip-tests mode would test 2 modules (1 direct + 1 downstream), skip tests for 1 (generated code, meta-modules)

Modules Scalpel would test (2)
  • camel-jbang-plugin-tui
  • camel-launcher-container
Modules with tests skipped (1)
  • camel-launcher

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (3 modules)
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: Launcher
  • Camel :: Launcher :: Container

⚙️ View full build and test results

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation of plain-text edit mode for the TUI source viewer with comprehensive tests (22 tests covering enter/cancel/save, Esc discard, paste, read-only files, markdown restore, and footer hints) and proper key isolation. CI passes.

A few cleanup items:

  1. Dead code: isSourceViewerPasteActive() in FilesBrowser.java (line 63) has zero callers — it's functionally identical to the new isSourceViewerTextInputActive(). Similarly, isSourceViewerSearchActive() in SourceTab.java (line 110) has zero callers after CamelMonitor was updated. Both should be removed.

  2. FQCNs in test: SourceViewerEditTest.java uses fully qualified java.util.concurrent.atomic.AtomicReference and java.util.List at 8 locations (lines 165, 166, 181, 182, 302, 303, 318, 319) despite already importing both types at lines 23-24. Per project convention, simple class names should be used.

  3. Redundant assignments: In saveEdit(), saveMessage = "Saved" and saveError = false at lines 497-498 are immediately overwritten by loadFile(path) which resets them. Only the post-reload assignments at lines 509-510 have effect.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@Test
void remoteLoadSourceIsNotEditable() {
MonitorContext ctx = new MonitorContext(
new java.util.concurrent.atomic.AtomicReference<>(java.util.List.of()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully qualified class names used here (and at lines 166, 181, 182, 302, 303, 318, 319) despite AtomicReference and List already being imported at lines 23-24. Per project convention: "Do NOT use fully qualified class names in Java code. Always add an import statement and use the simple class name."

Suggested change
new java.util.concurrent.atomic.AtomicReference<>(java.util.List.of()),
new AtomicReference<>(List.of()),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 40febda5f24AtomicReference and List now use imported simple names throughout the test file.

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

AI-generated comment on behalf of atiaomar1978-hub

Addressed @gnodet review in 186d59b4966:

  1. Removed unused FilesBrowser.isSourceViewerPasteActive() and SourceTab.isSourceViewerSearchActive().
  2. Replaced FQCNs with imported simple names in SourceViewerEditTest.
  3. Removed redundant pre-loadFile() save message assignments in SourceViewer.saveEdit().

SourceViewerEditTest re-run locally — all 22 tests pass.

cursoragent and others added 4 commits July 30, 2026 09:12
Allow toggling the source viewer into a TextArea-based edit mode for
local/writable files (dev mode or local folder). Press e to edit,
Esc to cancel, F5 to save. Process-sourced views remain read-only.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Route Esc cancel through SourceTab.handleEscape (CamelMonitor handles
Esc before tab keys). Block Tab focus-toggle while editing, restore
markdown mode on cancel, and clear stale save feedback on reload.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Forward keyboard input to the source viewer while editing even when file-list focus is active, and restore raw markdown view after save when the user had toggled preview off.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove unused paste/search helper methods, drop redundant saveEdit
assignments before reload, and use simple names in SourceViewerEditTest.

Co-authored-by: Cursor <cursoragent@cursor.com>
@atiaomar1978-hub
atiaomar1978-hub force-pushed the cursor/camel-24287-source-viewer-edit-26c6 branch from 186d59b to 40febda Compare July 30, 2026 16:20
@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

AI-generated comment on behalf of atiaomar1978-hub

Follow-up for @gnodet review:

  • All three cleanup items were addressed in 40febda5f24 (rebased onto current main):
    1. Removed unused FilesBrowser.isSourceViewerPasteActive() and SourceTab.isSourceViewerSearchActive() — consolidated on isSourceViewerTextInputActive().
    2. Replaced FQCNs with imported simple names in SourceViewerEditTest.
    3. Removed redundant pre-loadFile() save-message assignments in SourceViewer.saveEdit().

Branch rebased on latest main (4 commits). SourceViewerEditTest re-run locally — 22 tests, all green.

Ready for re-review.

@apupier
apupier requested a review from gnodet July 31, 2026 07:19

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after latest commits. All three previous review items are properly addressed:

  1. Dead code removalisSourceViewerPasteActive() and isSourceViewerSearchActive() removed and consolidated into isSourceViewerTextInputActive()
  2. FQCN cleanup — all FQCNs in SourceViewerEditTest.java replaced with imported simple names ✅
  3. Redundant assignments — pre-loadFile() save-message assignments removed from saveEdit(); save feedback now correctly set after reload ✅

Good test coverage with 22 tests covering enter/cancel/save, Esc discard, paste into editor, read-only guard, markdown mode restore, footer hints, Tab handling, and cross-tab key forwarding.

Minor suggestions for follow-up (non-blocking):

  • dev.tamboui.tui.event.KeyCode.ESCAPE at line 231 of SourceTab.java uses FQCN (matches pre-existing pattern at line 142 for KeyCode.TAB on main). Both could be cleaned up by adding import dev.tamboui.tui.event.KeyCode;.
  • exitEditMode(boolean reloadFromDisk) has an unused parameter — all call sites pass false. Could be simplified to parameterless exitEditMode().

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants