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

davsclaus pushed a commit to branch CAMEL-23648-run-folder
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0c764327029b84cb19a60617363397852befa954
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jun 1 09:43:23 2026 +0200

    CAMEL-23648: camel-jbang - TUI source view auto-scroll past license headers
    
    Co-Authored-By: Claude <[email protected]>
---
 .../dsl/jbang/core/commands/tui/RoutesTab.java     | 41 +++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
index 48de04ec6473..776695e05f19 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
@@ -1110,7 +1110,12 @@ class RoutesTab implements MonitorTab {
             idx++;
         }
 
-        int scrollTo = matchLine > 0 ? Math.max(0, matchLine - 2) : 0;
+        int scrollTo;
+        if (matchLine > 0) {
+            scrollTo = Math.max(0, matchLine - 2);
+        } else {
+            scrollTo = findLicenseHeaderEnd(codeLines);
+        }
         applySourceResult(routeId, sourceLocation, lines, scrollTo);
     }
 
@@ -1134,6 +1139,40 @@ class RoutesTab implements MonitorTab {
         });
     }
 
+    private static int findLicenseHeaderEnd(List<JsonObject> codeLines) {
+        // Auto-scroll past leading license/comment headers
+        boolean inBlock = false;
+        int lastCommentLine = -1;
+        for (int i = 0; i < codeLines.size(); i++) {
+            String code = objToString(codeLines.get(i).get("code")).trim();
+            if (i == 0 && code.isEmpty()) {
+                continue;
+            }
+            if (!inBlock && code.startsWith("/*")) {
+                inBlock = true;
+            }
+            if (inBlock) {
+                lastCommentLine = i;
+                if (code.contains("*/")) {
+                    inBlock = false;
+                }
+                continue;
+            }
+            // YAML/shell comment lines or XML comment lines at the top
+            if (code.startsWith("#") || code.startsWith("##") || 
code.startsWith("<!--")) {
+                lastCommentLine = i;
+                continue;
+            }
+            // Empty line right after comment block
+            if (lastCommentLine >= 0 && code.isEmpty()) {
+                lastCommentLine = i;
+                continue;
+            }
+            break;
+        }
+        return lastCommentLine >= 0 ? lastCommentLine + 1 : 0;
+    }
+
     private static String objToString(Object o) {
         return o != null ? o.toString() : "";
     }

Reply via email to