diff --git a/docs/pr-media/1698/workspace-double-click-rename.png b/docs/pr-media/1698/workspace-double-click-rename.png new file mode 100644 index 00000000..fb1dd9e9 Binary files /dev/null and b/docs/pr-media/1698/workspace-double-click-rename.png differ diff --git a/static/ui.js b/static/ui.js index 98409110..c58b2389 100644 --- a/static/ui.js +++ b/static/ui.js @@ -5685,6 +5685,7 @@ function _renderTreeItems(container, entries, depth){ // Name const nameEl=document.createElement('span'); nameEl.className='file-name';nameEl.textContent=item.name;nameEl.title=t('double_click_rename'); + nameEl.onclick=(e)=>e.stopPropagation(); nameEl.ondblclick=(e)=>{ e.stopPropagation(); // For directories, double-click navigates (breadcrumb view) diff --git a/tests/test_workspace_tree_rename.py b/tests/test_workspace_tree_rename.py new file mode 100644 index 00000000..fd6c401a --- /dev/null +++ b/tests/test_workspace_tree_rename.py @@ -0,0 +1,22 @@ +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parents[1] +UI_JS = (REPO_ROOT / "static" / "ui.js").read_text(encoding="utf-8") + + +def test_workspace_file_name_click_stops_before_dblclick_rename(): + """Clicking a file name must not bubble to the row open handler before dblclick rename.""" + name_start = UI_JS.index("const nameEl=document.createElement('span');") + dblclick_idx = UI_JS.index("nameEl.ondblclick=(e)=>", name_start) + click_idx = UI_JS.find("nameEl.onclick=(e)=>e.stopPropagation();", name_start, dblclick_idx) + + assert click_idx != -1, ( + "workspace file-tree name span must stop click propagation before its dblclick " + "rename handler so the row openFile() click does not win the first click" + ) + + +def test_workspace_file_row_click_still_opens_file_preview(): + """Only the name span should swallow clicks; the rest of the file row still opens preview.""" + assert "el.onclick=async()=>openFile(item.path);" in UI_JS