Skip to content

Commit 1b63a9e

Browse files
authored
GLSP-1245: Fix overflowing issue with command palette (#449)
Adjust CSS styling for the command palette to enable proper overflow without shifting the diagram itself. Fixes eclipse-glsp/glsp#1245
1 parent 79a4b50 commit 1b63a9e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/client/css/command-palette.css

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

1717
.command-palette {
18+
position: fixed;
1819
transition: opacity 0.3s linear;
1920
box-shadow:
2021
0 4px 8px 0 rgba(0, 0, 0, 0.2),
2122
0 6px 20px 0 rgba(0, 0, 0, 0.19);
23+
overflow: visible;
2224
}
2325

2426
.command-palette-suggestions {

packages/client/src/features/command-palette/command-palette.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
1616

17-
import { CommandPalette } from '@eclipse-glsp/sprotty';
17+
import { Bounds, CommandPalette, getWindowScroll, GModelElement, GModelRoot } from '@eclipse-glsp/sprotty';
1818
import { injectable } from 'inversify';
1919
import { CSS_HIDDEN_EXTENSION_CLASS, CSS_UI_EXTENSION_CLASS } from '../../base/ui-extension/ui-extension';
20+
import { getElements, isSelectableAndBoundsAware } from '../../utils/gmodel-util';
2021

2122
@injectable()
2223
export class GlspCommandPalette extends CommandPalette {
2324
protected override initializeContents(containerElement: HTMLElement): void {
2425
super.initializeContents(containerElement);
26+
containerElement.style.position = '';
2527
containerElement.classList.add(CSS_UI_EXTENSION_CLASS);
2628
}
2729

@@ -32,4 +34,42 @@ export class GlspCommandPalette extends CommandPalette {
3234
this.containerElement?.classList.add(CSS_HIDDEN_EXTENSION_CLASS);
3335
}
3436
}
37+
38+
protected override onBeforeShow(containerElement: HTMLElement, root: Readonly<GModelRoot>, ...selectedElementIds: string[]): void {
39+
let x = this.xOffset;
40+
let y = this.yOffset;
41+
42+
const selectedElements = getElements(root.index, selectedElementIds, isSelectableAndBoundsAware);
43+
if (selectedElements.length === 1) {
44+
const bounds = this.getAbsoluteBounds(selectedElements[0]);
45+
x += bounds.x + bounds.width;
46+
y += bounds.y;
47+
} else {
48+
const bounds = this.getAbsoluteBounds(root);
49+
x += bounds.x;
50+
y += bounds.y;
51+
}
52+
containerElement.style.left = `${x}px`;
53+
containerElement.style.top = `${y}px`;
54+
containerElement.style.width = `${this.defaultWidth}px`;
55+
}
56+
57+
protected getAbsoluteBounds(element: Readonly<GModelElement>): Bounds {
58+
let x = 0;
59+
let y = 0;
60+
let width = 0;
61+
let height = 0;
62+
63+
const svgElementId = this.domHelper.createUniqueDOMElementId(element);
64+
const svgElement = document.getElementById(svgElementId);
65+
if (svgElement) {
66+
const rect = svgElement.getBoundingClientRect();
67+
const scroll = getWindowScroll();
68+
x = rect.left + scroll.x;
69+
y = rect.top + scroll.y;
70+
width = rect.width;
71+
height = rect.height;
72+
}
73+
return { x, y, width, height };
74+
}
3575
}

0 commit comments

Comments
 (0)