Skip to content

Commit

Permalink
debt - adopt more $ over createElement (#242533)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Mar 4, 2025
1 parent 3df8270 commit 5d93bf3
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ export class ActivityBarCompositeBar extends PaneCompositeBar {
return; // prevent menu bar from installing twice #110720
}

this.menuBarContainer = document.createElement('div');
this.menuBarContainer.classList.add('menubar');
this.menuBarContainer = $('.menubar');

const content = assertIsDefined(this.element);
content.prepend(this.menuBarContainer);
Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { onDidChangeFullscreen } from '../../../../base/browser/browser.js';
import { hide, show } from '../../../../base/browser/dom.js';
import { $, hide, show } from '../../../../base/browser/dom.js';
import { Emitter, Event } from '../../../../base/common/event.js';
import { DisposableStore } from '../../../../base/common/lifecycle.js';
import { isNative } from '../../../../base/common/platform.js';
Expand Down Expand Up @@ -105,9 +105,7 @@ export class AuxiliaryEditorPart {
const auxiliaryWindow = disposables.add(await this.auxiliaryWindowService.open(options));

// Editor Part
const editorPartContainer = document.createElement('div');
editorPartContainer.classList.add('part', 'editor');
editorPartContainer.setAttribute('role', 'main');
const editorPartContainer = $('.part.editor', { role: 'main' });
editorPartContainer.style.position = 'relative';
auxiliaryWindow.container.appendChild(editorPartContainer);

Expand Down Expand Up @@ -315,7 +313,7 @@ class AuxiliaryEditorPartImpl extends EditorPart implements IAuxiliaryEditorPart
const result = this.mergeAllGroups(targetGroup, {
// Try to reduce the impact of closing the auxiliary window
// as much as possible by not changing existing editors
// in the main window.
// in the main window.
preserveExistingIndex: true
});
targetGroup.focus();
Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/browser/parts/editor/editorDropTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import './media/editordroptarget.css';
import { DataTransfers } from '../../../../base/browser/dnd.js';
import { addDisposableListener, DragAndDropObserver, EventHelper, EventType, getWindow, isAncestor } from '../../../../base/browser/dom.js';
import { $, addDisposableListener, DragAndDropObserver, EventHelper, EventType, getWindow, isAncestor } from '../../../../base/browser/dom.js';
import { renderFormattedText } from '../../../../base/browser/formattedTextRenderer.js';
import { RunOnceScheduler } from '../../../../base/common/async.js';
import { toDisposable } from '../../../../base/common/lifecycle.js';
Expand Down Expand Up @@ -84,8 +84,7 @@ class DropOverlay extends Themable {
const overlayOffsetHeight = this.getOverlayOffsetHeight();

// Container
const container = this.container = document.createElement('div');
container.id = DropOverlay.OVERLAY_ID;
const container = this.container = $('div', { id: DropOverlay.OVERLAY_ID });
container.style.top = `${overlayOffsetHeight}px`;

// Parent
Expand All @@ -97,8 +96,7 @@ class DropOverlay extends Themable {
}));

// Overlay
this.overlay = document.createElement('div');
this.overlay.classList.add('editor-group-overlay-indicator');
this.overlay = $('.editor-group-overlay-indicator');
container.appendChild(this.overlay);

if (this.enableDropIntoEditor) {
Expand Down
13 changes: 5 additions & 8 deletions src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EditorInput } from '../../../common/editor/editorInput.js';
import { SideBySideEditorInput } from '../../../common/editor/sideBySideEditorInput.js';
import { Emitter, Relay } from '../../../../base/common/event.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { Dimension, trackFocus, addDisposableListener, EventType, EventHelper, findParentWithClass, isAncestor, IDomNodePagePosition, isMouseEvent, isActiveElement, getWindow, getActiveElement } from '../../../../base/browser/dom.js';
import { Dimension, trackFocus, addDisposableListener, EventType, EventHelper, findParentWithClass, isAncestor, IDomNodePagePosition, isMouseEvent, isActiveElement, getWindow, getActiveElement, $ } from '../../../../base/browser/dom.js';
import { ServiceCollection } from '../../../../platform/instantiation/common/serviceCollection.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { ProgressBar } from '../../../../base/browser/ui/progressbar/progressbar.js';
Expand Down Expand Up @@ -208,16 +208,14 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.handleGroupContextKeys();

// Title container
this.titleContainer = document.createElement('div');
this.titleContainer.classList.add('title');
this.titleContainer = $('.title');
this.element.appendChild(this.titleContainer);

// Title control
this.titleControl = this._register(this.scopedInstantiationService.createInstance(EditorTitleControl, this.titleContainer, this.editorPartsView, this.groupsView, this, this.model));

// Editor container
this.editorContainer = document.createElement('div');
this.editorContainer.classList.add('editor-container');
this.editorContainer = $('.editor-container');
this.element.appendChild(this.editorContainer);

// Editor pane
Expand Down Expand Up @@ -406,8 +404,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
private createContainerToolbar(): void {

// Toolbar Container
const toolbarContainer = document.createElement('div');
toolbarContainer.classList.add('editor-group-container-toolbar');
const toolbarContainer = $('.editor-group-container-toolbar');
this.element.appendChild(toolbarContainer);

// Toolbar
Expand Down Expand Up @@ -2151,7 +2148,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

//#region ISerializableView

readonly element: HTMLElement = document.createElement('div');
readonly element: HTMLElement = $('div');

get minimumWidth(): number { return this.editorPane.minimumWidth; }
get minimumHeight(): number { return this.editorPane.minimumHeight; }
Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorPanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Severity from '../../../../base/common/severity.js';
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
import { EditorExtensions, EditorInputCapabilities, IEditorOpenContext, IVisibleEditorPane, isEditorOpenError } from '../../../common/editor.js';
import { EditorInput } from '../../../common/editor/editorInput.js';
import { Dimension, show, hide, IDomNodePagePosition, isAncestor, getActiveElement, getWindowById, isEditableElement } from '../../../../base/browser/dom.js';
import { Dimension, show, hide, IDomNodePagePosition, isAncestor, getActiveElement, getWindowById, isEditableElement, $ } from '../../../../base/browser/dom.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { IEditorPaneRegistry, IEditorPaneDescriptor } from '../../editor.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
Expand Down Expand Up @@ -360,8 +360,7 @@ export class EditorPanes extends Disposable {

// Create editor container as needed
if (!editorPane.getContainer()) {
const editorPaneContainer = document.createElement('div');
editorPaneContainer.classList.add('editor-instance');
const editorPaneContainer = $('.editor-instance');

// It is cruicial to append the container to its parent before
// passing on to the create() method of the pane so that the
Expand Down
6 changes: 2 additions & 4 deletions src/vs/workbench/browser/parts/editor/editorPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {

// Container
this.element = parent;
this.container = document.createElement('div');
this.container.classList.add('content');
this.container = $('.content');
if (this.windowId !== mainWindow.vscodeWindowId) {
this.container.classList.add('auxiliary');
}
Expand Down Expand Up @@ -1067,8 +1066,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
this._register(this.createEditorDropTarget(container, Object.create(null)));

// No drop in the editor
const overlay = document.createElement('div');
overlay.classList.add('drop-block-overlay');
const overlay = $('.drop-block-overlay');
parent.appendChild(overlay);

// Hide the block if a mouse down event occurs #99065
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/browser/parts/editor/editorPlaceholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export abstract class EditorPlaceholder extends EditorPane {
protected createEditor(parent: HTMLElement): void {

// Container
this.container = document.createElement('div');
this.container.className = 'monaco-editor-pane-placeholder';
this.container = $('.monaco-editor-pane-placeholder', {
tabIndex: 0 // enable focus support from the editor part (do not remove)
});
this.container.style.outline = 'none';
this.container.tabIndex = 0; // enable focus support from the editor part (do not remove)

// Custom Scrollbars
this.scrollbar = this._register(new DomScrollableElement(this.container, { horizontal: ScrollbarVisibility.Auto, vertical: ScrollbarVisibility.Auto }));
Expand Down Expand Up @@ -107,7 +107,7 @@ export abstract class EditorPlaceholder extends EditorPane {

// Label
const labelContainer = container.appendChild($('.editor-placeholder-label-container'));
const labelWidget = document.createElement('span');
const labelWidget = $('span');
labelWidget.textContent = truncatedLabel;
labelContainer.appendChild(labelWidget);

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorTabsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import './media/editortabscontrol.css';
import { localize } from '../../../../nls.js';
import { applyDragImage, DataTransfers } from '../../../../base/browser/dnd.js';
import { Dimension, getActiveWindow, getWindow, isMouseEvent } from '../../../../base/browser/dom.js';
import { $, Dimension, getActiveWindow, getWindow, isMouseEvent } from '../../../../base/browser/dom.js';
import { StandardMouseEvent } from '../../../../base/browser/mouseEvent.js';
import { ActionsOrientation, IActionViewItem, prepareActions } from '../../../../base/browser/ui/actionbar/actionbar.js';
import { IAction, ActionRunner } from '../../../../base/common/actions.js';
Expand Down Expand Up @@ -177,7 +177,7 @@ export abstract class EditorTabsControl extends Themable implements IEditorTabsC
}

protected createEditorActionsToolBar(parent: HTMLElement, classes: string[]): void {
this.editorActionsToolbarContainer = document.createElement('div');
this.editorActionsToolbarContainer = $('div');
this.editorActionsToolbarContainer.classList.add(...classes);
parent.appendChild(this.editorActionsToolbarContainer);

Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorTitleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import './media/editortitlecontrol.css';
import { Dimension, clearNode } from '../../../../base/browser/dom.js';
import { $, Dimension, clearNode } from '../../../../base/browser/dom.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IThemeService, Themable } from '../../../../platform/theme/common/themeService.js';
import { BreadcrumbsControl, BreadcrumbsControlFactory } from './breadcrumbsControl.js';
Expand Down Expand Up @@ -82,8 +82,7 @@ export class EditorTitleControl extends Themable {
}

// Breadcrumbs container
const breadcrumbsContainer = document.createElement('div');
breadcrumbsContainer.classList.add('breadcrumbs-below-tabs');
const breadcrumbsContainer = $('.breadcrumbs-below-tabs');
this.parent.appendChild(breadcrumbsContainer);

const breadcrumbsControlFactory = this.breadcrumbsControlDisposables.add(this.instantiationService.createInstance(BreadcrumbsControlFactory, breadcrumbsContainer, this.groupView, {
Expand Down
33 changes: 14 additions & 19 deletions src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ResourcesDropHandler, DraggedEditorIdentifier, DraggedEditorGroupIdenti
import { Color } from '../../../../base/common/color.js';
import { INotificationService } from '../../../../platform/notification/common/notification.js';
import { MergeGroupMode, IMergeGroupOptions } from '../../../services/editor/common/editorGroupsService.js';
import { addDisposableListener, EventType, EventHelper, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode, DragAndDropObserver, isMouseEvent, getWindow } from '../../../../base/browser/dom.js';
import { addDisposableListener, EventType, EventHelper, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode, DragAndDropObserver, isMouseEvent, getWindow, $ } from '../../../../base/browser/dom.js';
import { localize } from '../../../../nls.js';
import { IEditorGroupsView, EditorServiceImpl, IEditorGroupView, IInternalEditorOpenOptions, IEditorPartsView, prepareMoveCopyEditors } from './editor.js';
import { CloseEditorTabAction, UnpinEditorAction } from './editorActions.js';
Expand Down Expand Up @@ -170,15 +170,14 @@ export class MultiEditorTabsControl extends EditorTabsControl {
this.titleContainer = parent;

// Tabs and Actions Container (are on a single row with flex side-by-side)
this.tabsAndActionsContainer = document.createElement('div');
this.tabsAndActionsContainer.classList.add('tabs-and-actions-container');
this.tabsAndActionsContainer = $('.tabs-and-actions-container');
this.titleContainer.appendChild(this.tabsAndActionsContainer);

// Tabs Container
this.tabsContainer = document.createElement('div');
this.tabsContainer.setAttribute('role', 'tablist');
this.tabsContainer.draggable = true;
this.tabsContainer.classList.add('tabs-container');
this.tabsContainer = $('.tabs-container', {
role: 'tablist',
draggable: true
});
this._register(Gesture.addTarget(this.tabsContainer));

this.tabSizingFixedDisposables = this._register(new DisposableStore());
Expand Down Expand Up @@ -803,25 +802,23 @@ export class MultiEditorTabsControl extends EditorTabsControl {
private createTab(tabIndex: number, tabsContainer: HTMLElement, tabsScrollbar: ScrollableElement): HTMLElement {

// Tab Container
const tabContainer = document.createElement('div');
tabContainer.draggable = true;
tabContainer.setAttribute('role', 'tab');
tabContainer.classList.add('tab');
const tabContainer = $('.tab', {
draggable: true,
role: 'tab'
});

// Gesture Support
this._register(Gesture.addTarget(tabContainer));

// Tab Border Top
const tabBorderTopContainer = document.createElement('div');
tabBorderTopContainer.classList.add('tab-border-top-container');
const tabBorderTopContainer = $('.tab-border-top-container');
tabContainer.appendChild(tabBorderTopContainer);

// Tab Editor Label
const editorLabel = this.tabResourceLabels.create(tabContainer, { hoverTargetOverride: tabContainer });

// Tab Actions
const tabActionsContainer = document.createElement('div');
tabActionsContainer.classList.add('tab-actions');
const tabActionsContainer = $('.tab-actions');
tabContainer.appendChild(tabActionsContainer);

const that = this;
Expand All @@ -841,13 +838,11 @@ export class MultiEditorTabsControl extends EditorTabsControl {

// Tab Fade Hider
// Hides the tab fade to the right when tab action left and sizing shrink/fixed, ::after, ::before are already used
const tabShadowHider = document.createElement('div');
tabShadowHider.classList.add('tab-fade-hider');
const tabShadowHider = $('.tab-fade-hider');
tabContainer.appendChild(tabShadowHider);

// Tab Border Bottom
const tabBorderBottomContainer = document.createElement('div');
tabBorderBottomContainer.classList.add('tab-border-bottom-container');
const tabBorderBottomContainer = $('.tab-border-bottom-container');
tabContainer.appendChild(tabBorderBottomContainer);

// Eventing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EditorTabsControl } from './editorTabsControl.js';
import { ResourceLabel, IResourceLabel } from '../../labels.js';
import { TAB_ACTIVE_FOREGROUND, TAB_UNFOCUSED_ACTIVE_FOREGROUND } from '../../../common/theme.js';
import { EventType as TouchEventType, GestureEvent, Gesture } from '../../../../base/browser/touch.js';
import { addDisposableListener, EventType, EventHelper, Dimension, isAncestor, DragAndDropObserver, isHTMLElement } from '../../../../base/browser/dom.js';
import { addDisposableListener, EventType, EventHelper, Dimension, isAncestor, DragAndDropObserver, isHTMLElement, $ } from '../../../../base/browser/dom.js';
import { CLOSE_EDITOR_COMMAND_ID, UNLOCK_GROUP_COMMAND_ID } from './editorCommands.js';
import { Color } from '../../../../base/common/color.js';
import { assertIsDefined, assertAllDefined } from '../../../../base/common/types.js';
Expand Down Expand Up @@ -46,8 +46,7 @@ export class SingleEditorTabsControl extends EditorTabsControl {
// Gesture Support
this._register(Gesture.addTarget(titleContainer));

const labelContainer = document.createElement('div');
labelContainer.classList.add('label-container');
const labelContainer = $('.label-container');
titleContainer.appendChild(labelContainer);

// Editor Label
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/globalCompositeBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class GlobalCompositeBar extends Disposable {
) {
super();

this.element = document.createElement('div');
this.element = $('div');
const contextMenuAlignmentOptions = () => ({
anchorAlignment: configurationService.getValue('workbench.sideBar.location') === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT,
anchorAxisAlignment: AnchorAxisAlignment.HORIZONTAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IContextKeyService } from '../../../../platform/contextkey/common/conte
import { INotificationsCenterController, NotificationActionRunner } from './notificationsCommands.js';
import { NotificationsList } from './notificationsList.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { Dimension, isAncestorOfActiveElement } from '../../../../base/browser/dom.js';
import { $, Dimension, isAncestorOfActiveElement } from '../../../../base/browser/dom.js';
import { widgetShadow } from '../../../../platform/theme/common/colorRegistry.js';
import { IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
import { localize } from '../../../../nls.js';
Expand Down Expand Up @@ -149,22 +149,18 @@ export class NotificationsCenter extends Themable implements INotificationsCente
private create(): void {

// Container
this.notificationsCenterContainer = document.createElement('div');
this.notificationsCenterContainer.classList.add('notifications-center');
this.notificationsCenterContainer = $('.notifications-center');

// Header
this.notificationsCenterHeader = document.createElement('div');
this.notificationsCenterHeader.classList.add('notifications-center-header');
this.notificationsCenterHeader = $('.notifications-center-header');
this.notificationsCenterContainer.appendChild(this.notificationsCenterHeader);

// Header Title
this.notificationsCenterTitle = document.createElement('span');
this.notificationsCenterTitle.classList.add('notifications-center-header-title');
this.notificationsCenterTitle = $('span.notifications-center-header-title');
this.notificationsCenterHeader.appendChild(this.notificationsCenterTitle);

// Header Toolbar
const toolbarContainer = document.createElement('div');
toolbarContainer.classList.add('notifications-center-header-toolbar');
const toolbarContainer = $('.notifications-center-header-toolbar');
this.notificationsCenterHeader.appendChild(toolbarContainer);

const actionRunner = this._register(this.instantiationService.createInstance(NotificationActionRunner));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import './media/notificationsList.css';
import { localize } from '../../../../nls.js';
import { getWindow, isAncestorOfActiveElement, trackFocus } from '../../../../base/browser/dom.js';
import { $, getWindow, isAncestorOfActiveElement, trackFocus } from '../../../../base/browser/dom.js';
import { WorkbenchList } from '../../../../platform/list/browser/listService.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IListAccessibilityProvider, IListOptions } from '../../../../base/browser/ui/list/listWidget.js';
Expand Down Expand Up @@ -60,8 +60,7 @@ export class NotificationsList extends Disposable {
private createNotificationsList(): void {

// List Container
this.listContainer = document.createElement('div');
this.listContainer.classList.add('notifications-list-container');
this.listContainer = $('.notifications-list-container');

const actionRunner = this._register(this.instantiationService.createInstance(NotificationActionRunner));

Expand Down
Loading

0 comments on commit 5d93bf3

Please sign in to comment.