Skip to content

Commit 12b5528

Browse files
committed
frontend/aria/hotkey: improve dialog …
1 parent db006b2 commit 12b5528

File tree

4 files changed

+68
-29
lines changed

4 files changed

+68
-29
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Quick Navigation Dialog Styles
2+
// This file is part of CoCalc: Copyright © 2025 Sagemath, Inc.
3+
// License: MS-RSL – see LICENSE.md for details
4+
5+
@use '../../colors'
6+
7+
// CSS ellipsis style for tree node titles
8+
// Truncates text with ellipsis while preserving full text for search and hover
9+
.tree-node-ellipsis
10+
display: inline-block
11+
white-space: nowrap
12+
overflow: hidden
13+
text-overflow: ellipsis
14+
max-width: 350px
15+
16+
.quick-nav-tree
17+
// Prevent tree node content from wrapping to multiple lines
18+
.ant-tree-node-content-wrapper
19+
white-space: nowrap
20+
overflow: hidden
21+
text-overflow: ellipsis
22+
23+
&.ant-tree-node-selected
24+
background-color: colors.$COL_BLUE_L
25+
26+
// Highlight the entire node content wrapper when selected
27+
.ant-tree-node-selected .ant-tree-title
28+
display: inline-block
29+
padding: 0 2px
30+
border-radius: 2px

src/packages/frontend/app/hotkey/build-tree.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import {
1212
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
1313
import { Icon, IconName } from "@cocalc/frontend/components";
1414
import { filenameIcon } from "@cocalc/frontend/file-associations";
15-
import { FIXED_PROJECT_TABS } from "@cocalc/frontend/project/page/file-tab";
1615
import type { FixedTab } from "@cocalc/frontend/project/page/file-tab";
16+
import { FIXED_PROJECT_TABS } from "@cocalc/frontend/project/page/file-tab";
1717
import { COLORS } from "@cocalc/util/theme";
18-
import { trunc_middle } from "@cocalc/util/misc";
1918
import type { NavigationTreeNode } from "./dialog";
2019

2120
/**
@@ -202,7 +201,11 @@ export function buildNavigationTree(
202201

203202
tree.push({
204203
key: "current-file",
205-
title: trunc_middle(activeFileName, 50),
204+
title: (
205+
<span className="tree-node-ellipsis" title={activeFileName}>
206+
{activeFileName}
207+
</span>
208+
),
206209
defaultExpanded: true, // Always expand the current file
207210
children,
208211
});
@@ -335,7 +338,11 @@ function buildProjectNode(project: ProjectInfo): NavigationTreeNode {
335338
const fileIcon = filenameIcon(file.path);
336339
const fileNode: NavigationTreeNode = {
337340
key: `file-${file.path}`,
338-
title: trunc_middle(file.name, 30),
341+
title: (
342+
<span className="tree-node-ellipsis" title={file.path}>
343+
{file.name}
344+
</span>
345+
),
339346
icon: <Icon name={fileIcon} />,
340347
navigationData: {
341348
type: "file",
@@ -381,7 +388,11 @@ function buildProjectNode(project: ProjectInfo): NavigationTreeNode {
381388
const fileIcon = filenameIcon(filePath);
382389
return {
383390
key: `starred-file-${filePath}`,
384-
title: trunc_middle(fileName, 30),
391+
title: (
392+
<span className="tree-node-ellipsis" title={filePath}>
393+
{fileName}
394+
</span>
395+
),
385396
icon: <Icon name={fileIcon} />,
386397
navigationData: {
387398
type: "file",

src/packages/frontend/app/hotkey/dialog.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ export const QuickNavigationDialog: React.FC<QuickNavigationDialogProps> = ({
525525
// Then, transform for visual highlighting
526526
const transform = (nodes: NavigationTreeNode[]): NavigationTreeNode[] => {
527527
return nodes.map((node) => {
528-
const isSelected = node.key === selectedKey;
529528
const titleText = extractTextFromTitle(node.title);
530529
const isLeaf = !node.children || node.children.length === 0;
531530

@@ -534,23 +533,29 @@ export const QuickNavigationDialog: React.FC<QuickNavigationDialogProps> = ({
534533
// Apply search term highlighting only to leaf nodes (files, not container labels)
535534
if (searchValue && titleText.length > 0 && isLeaf) {
536535
const highlighted = highlightSearchMatches(titleText, searchValue);
537-
title = <span>{highlighted}</span>;
536+
// Preserve tree-node-ellipsis styling when wrapping highlighted content
537+
const hasEllipsisClass =
538+
React.isValidElement(node.title) &&
539+
typeof node.title.props === "object" &&
540+
node.title.props !== null &&
541+
"className" in node.title.props &&
542+
typeof node.title.props.className === "string" &&
543+
node.title.props.className.includes("tree-node-ellipsis");
544+
545+
if (hasEllipsisClass) {
546+
// Preserve the ellipsis class with highlighted content
547+
title = (
548+
<span className="tree-node-ellipsis" title={titleText}>
549+
{highlighted}
550+
</span>
551+
);
552+
} else {
553+
title = <span>{highlighted}</span>;
554+
}
538555
}
539556

540-
// Apply selection styling with pale blue background (not bold to preserve search highlighting)
541-
if (isSelected) {
542-
title = (
543-
<span
544-
style={{
545-
backgroundColor: "rgba(13, 110, 253, 0.15)",
546-
padding: "0 2px",
547-
borderRadius: "2px",
548-
}}
549-
>
550-
{title}
551-
</span>
552-
);
553-
}
557+
// Note: Selection styling is handled by CSS in _hotkey.sass via .ant-tree-node-selected class
558+
// Ant Design's Tree component applies this class when node key is in selectedKeys prop
554559

555560
return {
556561
...node,
@@ -633,14 +638,6 @@ export const QuickNavigationDialog: React.FC<QuickNavigationDialogProps> = ({
633638
}}
634639
className="quick-nav-tree"
635640
>
636-
<style>{`
637-
.quick-nav-tree .ant-tree-node-selected {
638-
background-color: transparent !important;
639-
}
640-
.quick-nav-tree .ant-tree-node-selected > span[class*="content"] {
641-
outline: none !important;
642-
}
643-
`}</style>
644641
<Tree
645642
treeData={transformedTreeData}
646643
expandedKeys={expandedKeys}

src/packages/frontend/index.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@use 'notifications/_style' as notifications-style
2828
@use 'account-button'
2929
@use 'admin/_style' as admin-style
30+
@use 'app/hotkey/_hotkey' as hotkey-style
3031
@use 'antd_fix'
3132

3233
@font-face

0 commit comments

Comments
 (0)