Skip to content

Commit aa88be5

Browse files
committed
feat: move Show-in-File-Tree into sidebar + always scroll-to-selected
- Replace the CCB file-label block with a hover-only binoculars button in the sidebar's #project-files-header, next to #collapse-folders. The file name was redundant with the live-preview heading and file tabs. - Merge the new button into the existing CollapseFolders extension so the two hover-revealed sidebar actions share a single owner and stylesheet. - DocumentCommandHandlers.handleShowInTree: after ProjectManager.showInTree resolves, scroll the selected tree node into view. Previously the auto-scroll in FileTreeView only fired on unselected→selected transitions, so re-invoking the command on an already-selected file was a no-op when the user had scrolled away. - Add mainview:CentralControlBar integ-test suite covering layout, CCB buttons, and the new sidebar hover button, using CommandManager's beforeExecuteCommand event instead of spies.
1 parent 22b2191 commit aa88be5

9 files changed

Lines changed: 293 additions & 48 deletions

File tree

src/document/DocumentCommandHandlers.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ define(function (require, exports, module) {
5454
Menus = require("command/Menus"),
5555
UrlParams = require("utils/UrlParams").UrlParams,
5656
StatusBar = require("widgets/StatusBar"),
57+
ViewUtils = require("utils/ViewUtils"),
5758
WorkspaceManager = require("view/WorkspaceManager"),
5859
LanguageManager = require("language/LanguageManager"),
5960
NewFileContentManager = require("features/NewFileContentManager"),
@@ -1957,7 +1958,16 @@ define(function (require, exports, module) {
19571958
CommandManager.execute(Commands.VIEW_HIDE_SIDEBAR);
19581959
}
19591960
SidebarTabs.setActiveTab(SidebarTabs.SIDEBAR_TAB_FILES);
1960-
ProjectManager.showInTree(activeFile);
1961+
// FileTreeView only auto-scrolls when the selection flips unselected→selected.
1962+
// Re-invoking the command on an already-selected file would otherwise be a
1963+
// no-op when the user has scrolled away — force-scroll the selected node
1964+
// into view so "Show in File Tree" always reveals the row.
1965+
ProjectManager.showInTree(activeFile).always(function () {
1966+
const $selected = $("#project-files-container .selected-node").first();
1967+
if ($selected.length) {
1968+
ViewUtils.scrollElementIntoView($("#project-files-container"), $selected, true);
1969+
}
1970+
});
19611971
}
19621972
}
19631973

src/extensionsIntegrated/CollapseFolders/main.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818
*
1919
*/
2020

21-
/* Displays a Collapse button in the sidebar area */
22-
/* when the button gets clicked, it closes all the directories recursively that are opened */
23-
/* Styling for the button is done in `../../styles/Extn-CollapseFolders.less` */
21+
/* Displays sidebar-hover action buttons: "show in file tree" (binoculars) and
22+
* "collapse all folders" (stacked chevrons). Both appear on sidebar hover so the
23+
* sidebar stays visually quiet when the user isn't interacting with it. */
24+
/* Styling for both buttons is done in `../../styles/Extn-CollapseFolders.less` */
2425
define(function (require, exports, module) {
2526
const AppInit = require("utils/AppInit");
27+
const CommandManager = require("command/CommandManager");
28+
const Commands = require("command/Commands");
2629
const ProjectManager = require("project/ProjectManager");
2730
const Strings = require("strings");
2831

32+
const SHOW_IN_TREE_SVG = '<svg class="show-in-tree-icon" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">' +
33+
'<path fill="currentColor" d="M4.5 1A1.5 1.5 0 0 0 3 2.5V3h4v-.5A1.5 1.5 0 0 0 5.5 1h-1zM7 4v1h2V4h4v.882a.5.5 0 0 0 .276.447l.895.447A1.5 1.5 0 0 1 15 7.118V13H9v-1.5a.5.5 0 0 1 .146-.354l.854-.853V9.5a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v.793l.854.853A.5.5 0 0 1 7 11.5V13H1V7.118a1.5 1.5 0 0 1 .83-1.342l.894-.447A.5.5 0 0 0 3 4.882V4h4zM1 14v.5A1.5 1.5 0 0 0 2.5 16h3A1.5 1.5 0 0 0 7 14.5V14H1zm8 0v.5a1.5 1.5 0 0 0 1.5 1.5h3a1.5 1.5 0 0 0 1.5-1.5V14H9zm4-11H9v-.5A1.5 1.5 0 0 1 10.5 1h1A1.5 1.5 0 0 1 13 2.5V3z"/>' +
34+
'</svg>';
35+
2936
/**
3037
* This is the main function that handles the closing of all the directories
3138
*/
@@ -52,30 +59,37 @@ define(function (require, exports, module) {
5259
}
5360
}
5461

62+
function _handleShowInTreeClick() {
63+
CommandManager.execute(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
64+
}
65+
5566
/**
56-
* This function is responsible to create the 'Collapse All' button
57-
* and append it to the sidebar area on the project-files-header
67+
* Append the sidebar hover actions: a "Show in File Tree" binoculars button
68+
* followed by the "Collapse All" chevron button. Both live in
69+
* #project-files-header and become visible only on #sidebar:hover.
5870
*/
59-
function createCollapseButton() {
71+
function createSidebarHoverButtons() {
6072
const $projectFilesHeader = $("#project-files-header");
61-
// make sure that we were able to get the project-files-header DOM element
6273
if ($projectFilesHeader.length === 0) {
6374
return;
6475
}
6576

66-
// create the collapse btn
77+
const $showInTreeBtn = $('<div id="show-in-file-tree" class="btn-alt-quiet" title="' +
78+
Strings.CMD_SHOW_IN_TREE + '">' + SHOW_IN_TREE_SVG + '</div>');
79+
$showInTreeBtn.on("click", _handleShowInTreeClick);
80+
$projectFilesHeader.append($showInTreeBtn);
81+
6782
const $collapseBtn = $(`
6883
<div id="collapse-folders" class="btn-alt-quiet" title="${Strings.COLLAPSE_ALL_FOLDERS}">
6984
<i class="fa-solid fa-chevron-down collapse-icon" aria-hidden="true"></i>
7085
<i class="fa-solid fa-chevron-up collapse-icon" aria-hidden="true"></i>
7186
</div>
7287
`);
73-
7488
$collapseBtn.on("click", handleCollapseBtnClick);
75-
$projectFilesHeader.append($collapseBtn); // append the btn to the project-files-header
89+
$projectFilesHeader.append($collapseBtn);
7690
}
7791

7892
AppInit.appReady(function () {
79-
createCollapseButton();
93+
createSidebarHoverButtons();
8094
});
8195
});

src/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,6 @@
964964
<div class="ccb-divider"></div>
965965
<div class="ccb-group ccb-group-nav">
966966
<a href="#" id="searchNav" class="ccb-btn"><i class="fa-solid fa-magnifying-glass"></i></a>
967-
<a href="#" id="ccbShowInTreeBtn" class="ccb-btn" title="Show in File Tree">
968-
<svg class="ccb-binoculars-icon" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
969-
<path fill="currentColor" d="M4.5 1A1.5 1.5 0 0 0 3 2.5V3h4v-.5A1.5 1.5 0 0 0 5.5 1h-1zM7 4v1h2V4h4v.882a.5.5 0 0 0 .276.447l.895.447A1.5 1.5 0 0 1 15 7.118V13H9v-1.5a.5.5 0 0 1 .146-.354l.854-.853V9.5a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v.793l.854.853A.5.5 0 0 1 7 11.5V13H1V7.118a1.5 1.5 0 0 1 .83-1.342l.894-.447A.5.5 0 0 0 3 4.882V4h4zM1 14v.5A1.5 1.5 0 0 0 2.5 16h3A1.5 1.5 0 0 0 7 14.5V14H1zm8 0v.5a1.5 1.5 0 0 0 1.5 1.5h3a1.5 1.5 0 0 0 1.5-1.5V14H9zm4-11H9v-.5A1.5 1.5 0 0 1 10.5 1h1A1.5 1.5 0 0 1 13 2.5V3z"/>
970-
</svg>
971-
</a>
972967
<a href="#" id="navBackButton" class="ccb-btn"><i class="fa-solid fa-arrow-left"></i></a>
973968
<a href="#" id="navForwardButton" class="ccb-btn"><i class="fa-solid fa-arrow-right"></i></a>
974969
</div>

src/styles/CentralControlBar.less

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@
7373
pointer-events: none;
7474
}
7575

76-
svg.ccb-binoculars-icon {
77-
width: 15px;
78-
height: 15px;
79-
pointer-events: none;
80-
}
81-
8276
&:hover {
8377
color: @project-panel-text-1;
8478
background-color: rgba(255, 255, 255, 0.08);
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1-
#collapse-folders {
1+
#collapse-folders,
2+
#show-in-file-tree {
23
display: flex;
3-
flex-direction: column;
44
align-items: center;
55
justify-content: center;
66
padding: 0.2em 0.65em;
77
margin-top: 0.1em;
88
position: absolute !important;
9-
right: 0;
109
opacity: 0;
1110
visibility: hidden;
1211
transition:
1312
opacity 0.2s ease-in-out,
1413
visibility 0.2s ease-in-out;
14+
}
15+
16+
#collapse-folders {
17+
flex-direction: column;
18+
right: 0;
1519

1620
.collapse-icon {
1721
font-size: 0.5em;
1822
line-height: 1;
1923
}
2024
}
2125

22-
#sidebar:hover #collapse-folders {
26+
#show-in-file-tree {
27+
// Sit to the left of #collapse-folders.
28+
right: 24px;
29+
30+
.show-in-tree-icon {
31+
// Sized to match the combined stacked-chevron glyph of #collapse-folders.
32+
width: 11px;
33+
height: 11px;
34+
pointer-events: none;
35+
}
36+
}
37+
38+
#sidebar:hover #collapse-folders,
39+
#sidebar:hover #show-in-file-tree {
2340
opacity: 1;
2441
visibility: visible;
2542
}

src/view/CentralControlBar.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ define(function (require, exports, module) {
261261
e.preventDefault();
262262
_executeCmd(Commands.VIEW_HIDE_SIDEBAR);
263263
});
264-
$("#ccbShowInTreeBtn").on("click", function (e) {
265-
e.preventDefault();
266-
_executeCmd(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
267-
});
268264
}
269265

270266
const _toggleDesignModeCommand = CommandManager.register(Strings.CMD_TOGGLE_DESIGN_MODE,
@@ -288,7 +284,6 @@ define(function (require, exports, module) {
288284
// navForwardButton get their localized titles from NavigationProvider.)
289285
$("#ccbCollapseEditorBtn").attr("title", Strings.CCB_SWITCH_TO_DESIGN_MODE);
290286
$("#ccbSidebarToggleBtn").attr("title", Strings.CMD_TOGGLE_SIDEBAR);
291-
$("#ccbShowInTreeBtn").attr("title", Strings.CMD_SHOW_IN_TREE);
292287
$("#ccbUndoBtn").attr("title", Strings.CMD_UNDO);
293288
$("#ccbRedoBtn").attr("title", Strings.CMD_REDO);
294289
$("#ccbSaveBtn").attr("title", Strings.CMD_FILE_SAVE);

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ define(function (require, exports, module) {
9292
require("spec/ExtensionUtils-integ-test");
9393
require("spec/InlineEditorProviders-integ-test");
9494
require("spec/PreferencesManager-integ-test");
95+
require("spec/CentralControlBar-integ-test");
9596
require("spec/MainViewFactory-integ-test");
9697
require("spec/MainViewManager-integ-test");
9798
require("spec/SidebarTabs-integ-test");

test/control-bar-tests-todo.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,30 @@ Keep this file updated as we add coverage; remove lines as suites land.
3333
- [ ] `#ccbSidebarToggleBtn` executes `VIEW_HIDE_SIDEBAR` and the icon flips
3434
`fa-angles-left``fa-angles-right` on panelCollapsed/panelExpanded.
3535
- [ ] The old `#sidebar-toggle-btn` in the menubar is NOT in the DOM.
36-
- [ ] `#ccbShowInTreeBtn` is rendered in `.ccb-group-nav` directly below
37-
`#searchNav` and has a `title` of `Strings.CMD_SHOW_IN_TREE`.
38-
- [ ] Clicking `#ccbShowInTreeBtn` executes `NAVIGATE_SHOW_IN_FILE_TREE` (if
39-
sidebar was hidden, it re-opens as part of the command).
40-
- [ ] Binoculars `<svg>` renders and inherits `.ccb-btn` color
41-
(`currentColor` on the path).
42-
- [ ] Neither `#ccbFileLabel`, `.ccb-group-file`, `.ccb-file-label`,
43-
`.ccb-file-name`, nor `.ccb-file-dot` exists in the DOM or in the
44-
compiled CSS.
36+
- [ ] `.ccb-group-nav` holds exactly `searchNav`, `navBackButton`,
37+
`navForwardButton` — no show-in-tree button lives in the CCB.
38+
39+
## 2a. #show-in-file-tree button (sidebar)
40+
41+
- [ ] `#show-in-file-tree` is a child of `#project-files-header` and sits
42+
before `#collapse-folders` in DOM order. Title equals
43+
`Strings.CMD_SHOW_IN_TREE`.
44+
- [ ] Binoculars `<svg>` uses `fill="currentColor"` so the glyph tracks the
45+
sidebar text color.
46+
- [ ] Button is hidden by default (`opacity: 0`, `visibility: hidden`) and
47+
only shows on `#sidebar:hover`, matching the `#collapse-folders`
48+
affordance.
49+
- [ ] Clicking `#show-in-file-tree` executes `NAVIGATE_SHOW_IN_FILE_TREE`.
4550

4651
## 3. Toggle Design Mode command
4752

4853
- [ ] `Commands.VIEW_TOGGLE_DESIGN_MODE === "view.toggleDesignMode"` is
4954
registered at module load, visible via `CommandManager.get`.
50-
- [ ] Default keybinding: `Ctrl-F11` (from `base-config/keyboard.json`).
51-
- [ ] File menu has "Toggle Design Mode" directly below "Live Preview" and
52-
above "Reload Live Preview".
5355
- [ ] Command's checked state mirrors `WorkspaceManager.isInDesignMode()` on
5456
both entry and exit.
55-
- [ ] Clicking `#ccbCollapseEditorBtn` routes through the command
56-
(verify via a spy on `CommandManager.execute`).
57-
- [ ] Icon swap: `fa-feather` (expanded) ↔ `fa-code` (design mode). Title
58-
swap: "Switch to Visual Edit" ↔ "Switch to Code Editor".
57+
- [ ] Clicking `#ccbCollapseEditorBtn`toggles design mode
58+
- [ ] Icon swap: `pen-nib svg` (expanded) ↔ `fa-code` (design mode). Title
59+
swap: "Switch to desin mode" ↔ "Switch to Code Editor".(please see the exact string to check.)
5960

6061
## 4. Enter design mode
6162

0 commit comments

Comments
 (0)