fix: debug widget layout updates

Use customized `PanelLayout#removeWidget` and
`PanelLayout#insertWidget` logic for the layout
updates. The customized functions ensure no side
effect if adding/removing the widget to/from the
layout but it's already present/absent.

Unlike the default [`PanelLayout#removeWidget`](9f5e11025b/packages/widgets/src/panellayout.ts (L154-L156))
behavior, do not try to remove the widget if it's
not present (has a negative index). Otherwise,
required widgets might be removed based on the
default [`ArrayExt#removeAt`](9f5e11025b/packages/algorithm/src/array.ts (L1075-L1077))
behavior.

Closes: arduino/arduino-ide#2354

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2024-02-08 10:21:09 +01:00
committed by Akos Kitta
parent 74c580175b
commit ca779e5cf2
3 changed files with 182 additions and 11 deletions

View File

@@ -1,8 +1,5 @@
import {
codicon,
PanelLayout,
Widget,
} from '@theia/core/lib/browser/widgets/widget';
import { codicon } from '@theia/core/lib/browser/widgets/widget';
import { Widget } from '@theia/core/shared/@phosphor/widgets';
import {
inject,
injectable,
@@ -10,6 +7,10 @@ import {
} from '@theia/core/shared/inversify';
import { DebugWidget as TheiaDebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
import { DebugDisabledStatusMessageSource } from '../../contributions/debug';
import {
removeWidgetIfPresent,
unshiftWidgetIfNotPresent,
} from '../dialogs/widgets';
@injectable()
export class DebugWidget extends TheiaDebugWidget {
@@ -38,12 +39,10 @@ export class DebugWidget extends TheiaDebugWidget {
this.messageNode.textContent = message ?? '';
const enabled = !message;
updateVisibility(enabled, this.toolbar, this.sessionWidget);
if (this.layout instanceof PanelLayout) {
if (enabled) {
this.layout.removeWidget(this.statusMessageWidget);
} else {
this.layout.insertWidget(0, this.statusMessageWidget);
}
if (enabled) {
removeWidgetIfPresent(this.layout, this.statusMessageWidget);
} else {
unshiftWidgetIfNotPresent(this.layout, this.statusMessageWidget);
}
this.title.iconClass = enabled ? codicon('debug-alt') : 'fa fa-ban'; // TODO: find a better icon?
});