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

lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/rocketmq-studio by this push:
     new d520c5ba fix: match navigation routes and preserve editing shortcuts 
(#625)
d520c5ba is described below

commit d520c5ba836862fae2dc4fc74c65a249e8e6128e
Author: yx9o <[email protected]>
AuthorDate: Tue Jul 28 20:54:22 2026 +0800

    fix: match navigation routes and preserve editing shortcuts (#625)
---
 web/src/layouts/navigationSearch.test.ts | 27 +++++++++++++++++++++++++++
 web/src/layouts/navigationSearch.ts      | 20 ++++++++++++++++++--
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/web/src/layouts/navigationSearch.test.ts 
b/web/src/layouts/navigationSearch.test.ts
index b6a626c7..be107851 100644
--- a/web/src/layouts/navigationSearch.test.ts
+++ b/web/src/layouts/navigationSearch.test.ts
@@ -29,6 +29,11 @@ describe('navigation search helpers', () => {
     expect(filterNavigationEntries(entries, '集群')).toEqual([entries[0]]);
   });
 
+  it('filters by route keys case-insensitively', () => {
+    expect(filterNavigationEntries(entries, 'CLUSTER')).toEqual([entries[0]]);
+    expect(filterNavigationEntries(entries, 
'/settings')).toEqual([entries[1]]);
+  });
+
   it('recognizes Control/Command-K but rejects alternative shortcuts', () => {
     expect(
       isNavigationSearchShortcut({ key: 'k', ctrlKey: true, metaKey: false, 
altKey: false }),
@@ -43,4 +48,26 @@ describe('navigation search helpers', () => {
       isNavigationSearchShortcut({ key: 'k', ctrlKey: true, metaKey: false, 
altKey: true }),
     ).toBe(false);
   });
+
+  it('does not capture the shortcut from editable elements', () => {
+    const input = document.createElement('input');
+    const textarea = document.createElement('textarea');
+    const select = document.createElement('select');
+    const editable = document.createElement('div');
+    editable.setAttribute('contenteditable', 'true');
+    const editableChild = document.createElement('span');
+    editable.appendChild(editableChild);
+
+    for (const target of [input, textarea, select, editable, editableChild]) {
+      expect(
+        isNavigationSearchShortcut({
+          key: 'k',
+          ctrlKey: true,
+          metaKey: false,
+          altKey: false,
+          target,
+        }),
+      ).toBe(false);
+    }
+  });
 });
diff --git a/web/src/layouts/navigationSearch.ts 
b/web/src/layouts/navigationSearch.ts
index 422934d3..04c58f7d 100644
--- a/web/src/layouts/navigationSearch.ts
+++ b/web/src/layouts/navigationSearch.ts
@@ -29,7 +29,11 @@ export function filterNavigationEntries(
 ): NavigationSearchEntry[] {
   const normalizedQuery = query.trim().toLocaleLowerCase();
   if (!normalizedQuery) return entries;
-  return entries.filter((entry) => 
entry.label.toLocaleLowerCase().includes(normalizedQuery));
+  return entries.filter(
+    (entry) =>
+      entry.label.toLocaleLowerCase().includes(normalizedQuery) ||
+      entry.key.toLocaleLowerCase().includes(normalizedQuery),
+  );
 }
 
 export function isNavigationSearchShortcut(event: {
@@ -37,6 +41,18 @@ export function isNavigationSearchShortcut(event: {
   metaKey: boolean;
   ctrlKey: boolean;
   altKey: boolean;
+  target?: EventTarget | null;
 }): boolean {
-  return event.key.toLocaleLowerCase() === 'k' && (event.metaKey || 
event.ctrlKey) && !event.altKey;
+  const isEditableTarget =
+    event.target instanceof Element &&
+    event.target.closest(
+      'input, textarea, select, 
[contenteditable]:not([contenteditable="false"])',
+    ) !== null;
+
+  return (
+    event.key.toLocaleLowerCase() === 'k' &&
+    (event.metaKey || event.ctrlKey) &&
+    !event.altKey &&
+    !isEditableTarget
+  );
 }

Reply via email to