Skip to content

Commit c55f16f

Browse files
committed
Fix: Preserve multiple consecutive spaces in Theia UI elements
Fixes: #16865 PROBLEM: - Multiple consecutive spaces in file/folder names were collapsed to single space - HTML whitespace normalization and textContent API both collapse spaces CSS CHANGES: - tree.css: Applied white-space: pre to .theia-TreeNodeSegment and .theia-TreeNodeSegmentGrow - dialog.css: Applied white-space: pre-wrap to dialog content (li, div) - tabs.css: Applied white-space: pre-wrap to tab hover title and caption - tooltip.css: Applied white-space: pre-wrap to .theia-tooltip - breadcrumbs.css: Applied white-space: pre-wrap to breadcrumb labels - tree-decorators.css: Applied white-space: pre to decorator badges JAVASCRIPT CHANGE: - tab-bars.ts (handleMouseEnterEvent): Replace consecutive spaces with non-breaking spaces (\u00A0) before passing to hover service RATIONALE: - CSS white-space: pre/pre-wrap handles directly rendered HTML elements - JavaScript solution needed for tooltips because hover-service.ts uses textContent which normalizes whitespace BEFORE CSS is applied - Non-breaking spaces (\u00A0) are not collapsed by textContent API - Used 'pre' for short content (tree nodes, badges) to prevent wrapping - Used 'pre-wrap' for long content (tooltips, dialogs, paths) to allow wrapping Fix: Fixed linting issues.
1 parent 980aa62 commit c55f16f

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed

packages/core/src/browser/shell/tab-bars.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,10 @@ export class TabBarRenderer extends TabBar.Renderer {
644644
} else if (title.caption) {
645645
const position = this.tabBar.orientation === 'horizontal' ? 'bottom' : 'right';
646646
const tooltip = ArrayUtils.coalesce([title.caption, ...this.getDecorationData(title, 'tooltip')]).join(' - ');
647+
// Preserve multiple consecutive spaces by replacing with non-breaking spaces
648+
const preservedTooltip = tooltip.replace(/ {2,}/g, match => '\u00A0'.repeat(match.length));
647649
this.hoverService.requestHover({
648-
content: tooltip,
650+
content: preservedTooltip,
649651
target: event.currentTarget,
650652
position
651653
});

packages/core/src/browser/style/breadcrumbs.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
display: flex;
4545
align-items: center;
4646
flex: 0 1 auto;
47-
white-space: nowrap;
47+
white-space: pre;
4848
align-self: center;
4949
height: 100%;
5050
color: var(--theia-breadcrumb-foreground);
@@ -118,7 +118,7 @@
118118
display: flex;
119119
align-items: center;
120120
flex: 0 1 auto;
121-
white-space: nowrap;
121+
white-space: pre;
122122
cursor: pointer;
123123
outline: none;
124124
padding: 0.25rem 0.25rem 0.25rem 0.25rem;

packages/core/src/browser/style/dialog.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
overflow-y: auto;
7171
}
7272

73+
/* Preserve multiple consecutive spaces in dialog content */
74+
.lm-Widget.dialogOverlay .dialogContent li,
75+
.lm-Widget.dialogOverlay .dialogContent div {
76+
white-space: pre-wrap;
77+
}
78+
7379
.lm-Widget.dialogOverlay .dialogControl {
7480
padding: calc(var(--theia-ui-padding) * 2);
7581
display: flex;
@@ -118,7 +124,7 @@
118124
.theia-dialog-node-segment {
119125
flex-grow: 0;
120126
user-select: none;
121-
white-space: nowrap;
127+
white-space: pre;
122128
}
123129

124130
.theia-dialog-icon {

packages/core/src/browser/style/tabs.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
color: var(--theia-descriptionForeground);
116116
flex: 1 1 auto;
117117
overflow: hidden;
118-
white-space: nowrap;
118+
white-space: pre;
119119
}
120120

121121
.lm-TabBar-tail {
@@ -536,6 +536,7 @@
536536
font-weight: bolder;
537537
max-width: var(--theia-hover-preview-width);
538538
word-wrap: break-word;
539+
white-space: pre-wrap !important;
539540
font-size: medium;
540541
margin: 0px 0px;
541542
}
@@ -544,6 +545,7 @@
544545
font-size: small;
545546
max-width: var(--theia-hover-preview-width);
546547
word-wrap: break-word;
548+
white-space: pre-wrap !important;
547549
margin: 0px 0px;
548550
margin-top: 4px;
549551
}

packages/core/src/browser/style/tooltip.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
background: var(--theia-editorHoverWidget-background) !important;
2020
border: 1px solid !important;
2121
border-color: var(--theia-editorHoverWidget-border) !important;
22+
white-space: pre-wrap !important;
2223
}
2324

2425
/* Hide tooltip arrow */

packages/core/src/browser/style/tree-decorators.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
********************************************************************************/
1616

1717
.theia-caption-prefix {
18-
white-space: nowrap;
18+
white-space: pre;
1919
padding-right: 2px;
2020
}
2121

2222
.theia-caption-suffix {
23-
white-space: nowrap;
23+
white-space: pre;
2424
padding: 0px 2px 0px 2px;
2525
}
2626

packages/core/src/browser/style/tree.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
align-items: center;
149149
flex-grow: 0;
150150
user-select: none;
151-
white-space: nowrap;
151+
white-space: pre;
152152
}
153153

154154
.theia-TreeNodeSegment.flex {
@@ -159,7 +159,7 @@
159159
flex-grow: 1 !important;
160160
overflow: hidden;
161161
text-overflow: ellipsis;
162-
white-space: nowrap;
162+
white-space: pre;
163163
}
164164

165165
.theia-TreeNodeTail {

0 commit comments

Comments
 (0)