mirror of
https://github.com/Microsoft/vscode
synced 2024-09-17 17:46:22 +00:00
Remove notebook editor decoration type (#151574)
* Remove the notebookEditorDecorationType API proposal Fixes #146838 * Remove all the infastructure around the now removed notebookEditorDecorationType api
This commit is contained in:
parent
32ba8bcab6
commit
8b0b3ee72e
|
@ -24,7 +24,6 @@
|
|||
"notebookControllerKind",
|
||||
"notebookDebugOptions",
|
||||
"notebookDeprecated",
|
||||
"notebookEditorDecorationType",
|
||||
"notebookEditorEdit",
|
||||
"notebookLiveShare",
|
||||
"notebookMessaging",
|
||||
|
|
|
@ -93,11 +93,6 @@ suite('vscode', function () {
|
|||
assertNoRpcFromEntry([item, 'TreeView']);
|
||||
});
|
||||
|
||||
test('no rpc, createNotebookEditorDecorationType(...)', function () {
|
||||
const item = vscode.notebooks.createNotebookEditorDecorationType({ top: {} });
|
||||
dispo.push(item);
|
||||
assertNoRpcFromEntry([item, 'NotebookEditorDecorationType']);
|
||||
});
|
||||
|
||||
test('no rpc, createNotebookController(...)', function () {
|
||||
const ctrl = vscode.notebooks.createNotebookController('foo', 'bar', '');
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
"notebookControllerKind",
|
||||
"notebookDebugOptions",
|
||||
"notebookDeprecated",
|
||||
"notebookEditorDecorationType",
|
||||
"notebookLiveShare",
|
||||
"notebookMessaging",
|
||||
"notebookMime"
|
||||
|
|
|
@ -7,7 +7,6 @@ import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
|
|||
import { getNotebookEditorFromEditorPane, INotebookEditor, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { ExtHostContext, ExtHostNotebookEditorsShape, ICellEditOperationDto, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
|
@ -165,22 +164,6 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
|
|||
}
|
||||
}
|
||||
|
||||
$registerNotebookEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void {
|
||||
this._notebookEditorService.registerEditorDecorationType(key, options);
|
||||
}
|
||||
|
||||
$removeNotebookEditorDecorationType(key: string): void {
|
||||
this._notebookEditorService.removeEditorDecorationType(key);
|
||||
}
|
||||
|
||||
$trySetDecorations(id: string, range: ICellRange, key: string): void {
|
||||
const editor = this._notebookEditorService.getNotebookEditor(id);
|
||||
if (editor) {
|
||||
const notebookEditor = editor as INotebookEditor;
|
||||
notebookEditor.setEditorDecorations(key, range);
|
||||
}
|
||||
}
|
||||
|
||||
$trySetSelections(id: string, ranges: ICellRange[]): void {
|
||||
const editor = this._notebookEditorService.getNotebookEditor(id);
|
||||
if (!editor) {
|
||||
|
|
|
@ -158,7 +158,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadBulkEdits)));
|
||||
const extHostNotebook = rpcProtocol.set(ExtHostContext.ExtHostNotebook, new ExtHostNotebookController(rpcProtocol, extHostCommands, extHostDocumentsAndEditors, extHostDocuments, extensionStoragePaths));
|
||||
const extHostNotebookDocuments = rpcProtocol.set(ExtHostContext.ExtHostNotebookDocuments, new ExtHostNotebookDocuments(extHostNotebook));
|
||||
const extHostNotebookEditors = rpcProtocol.set(ExtHostContext.ExtHostNotebookEditors, new ExtHostNotebookEditors(extHostLogService, rpcProtocol, extHostNotebook));
|
||||
const extHostNotebookEditors = rpcProtocol.set(ExtHostContext.ExtHostNotebookEditors, new ExtHostNotebookEditors(extHostLogService, extHostNotebook));
|
||||
const extHostNotebookKernels = rpcProtocol.set(ExtHostContext.ExtHostNotebookKernels, new ExtHostNotebookKernels(rpcProtocol, initData, extHostNotebook, extHostCommands, extHostLogService));
|
||||
const extHostNotebookRenderers = rpcProtocol.set(ExtHostContext.ExtHostNotebookRenderers, new ExtHostNotebookRenderers(rpcProtocol, extHostNotebook));
|
||||
const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
|
||||
|
@ -1146,10 +1146,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
registerNotebookCellStatusBarItemProvider: (notebookType: string, provider: vscode.NotebookCellStatusBarItemProvider) => {
|
||||
return extHostNotebook.registerNotebookCellStatusBarItemProvider(extension, notebookType, provider);
|
||||
},
|
||||
createNotebookEditorDecorationType(options: vscode.NotebookDecorationRenderOptions): vscode.NotebookEditorDecorationType {
|
||||
checkProposedApiEnabled(extension, 'notebookEditorDecorationType');
|
||||
return extHostNotebookEditors.createNotebookEditorDecorationType(options);
|
||||
},
|
||||
createRendererMessaging(rendererId) {
|
||||
return extHostNotebookRenderers.createRendererMessaging(extension, rendererId);
|
||||
},
|
||||
|
|
|
@ -959,10 +959,7 @@ export interface MainThreadNotebookShape extends IDisposable {
|
|||
export interface MainThreadNotebookEditorsShape extends IDisposable {
|
||||
$tryShowNotebookDocument(uriComponents: UriComponents, viewType: string, options: INotebookDocumentShowOptions): Promise<string>;
|
||||
$tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType): Promise<void>;
|
||||
$registerNotebookEditorDecorationType(key: string, options: notebookCommon.INotebookDecorationRenderOptions): void;
|
||||
$removeNotebookEditorDecorationType(key: string): void;
|
||||
$trySetSelections(id: string, range: ICellRange[]): void;
|
||||
$trySetDecorations(id: string, range: ICellRange, decorationKey: string): void;
|
||||
$tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperationDto[]): Promise<boolean>;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ export class ExtHostNotebookEditor {
|
|||
private _viewColumn?: vscode.ViewColumn;
|
||||
|
||||
private _visible: boolean = false;
|
||||
private readonly _hasDecorationsForKey = new Set<string>();
|
||||
|
||||
private _editor?: vscode.NotebookEditor;
|
||||
|
||||
|
@ -142,9 +141,6 @@ export class ExtHostNotebookEditor {
|
|||
callback(edit);
|
||||
return that._applyEdit(edit.finalize());
|
||||
},
|
||||
setDecorations(decorationType, range) {
|
||||
return that.setDecorations(decorationType, range);
|
||||
}
|
||||
};
|
||||
|
||||
ExtHostNotebookEditor.apiEditorsToExtHost.set(this._editor, this);
|
||||
|
@ -211,22 +207,4 @@ export class ExtHostNotebookEditor {
|
|||
|
||||
return this._proxy.$tryApplyEdits(this.id, editData.documentVersionId, compressedEdits);
|
||||
}
|
||||
|
||||
setDecorations(decorationType: vscode.NotebookEditorDecorationType, range: vscode.NotebookRange): void {
|
||||
if (range.isEmpty && !this._hasDecorationsForKey.has(decorationType.key)) {
|
||||
// avoid no-op call to the renderer
|
||||
return;
|
||||
}
|
||||
if (range.isEmpty) {
|
||||
this._hasDecorationsForKey.delete(decorationType.key);
|
||||
} else {
|
||||
this._hasDecorationsForKey.add(decorationType.key);
|
||||
}
|
||||
|
||||
return this._proxy.$trySetDecorations(
|
||||
this.id,
|
||||
extHostConverter.NotebookRange.from(range),
|
||||
decorationType.key
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,33 +4,12 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { IdGenerator } from 'vs/base/common/idGenerator';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { ExtHostNotebookEditorsShape, INotebookEditorPropertiesChangeData, INotebookEditorViewColumnInfo, MainContext, MainThreadNotebookEditorsShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostNotebookEditorsShape, INotebookEditorPropertiesChangeData, INotebookEditorViewColumnInfo } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import type * as vscode from 'vscode';
|
||||
|
||||
class NotebookEditorDecorationType {
|
||||
|
||||
private static readonly _Keys = new IdGenerator('NotebookEditorDecorationType');
|
||||
|
||||
readonly value: vscode.NotebookEditorDecorationType;
|
||||
|
||||
constructor(proxy: MainThreadNotebookEditorsShape, options: vscode.NotebookDecorationRenderOptions) {
|
||||
const key = NotebookEditorDecorationType._Keys.nextId();
|
||||
proxy.$registerNotebookEditorDecorationType(key, typeConverters.NotebookDecorationRenderOptions.from(options));
|
||||
|
||||
this.value = {
|
||||
key,
|
||||
dispose() {
|
||||
proxy.$removeNotebookEditorDecorationType(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {
|
||||
|
||||
|
@ -42,16 +21,8 @@ export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {
|
|||
|
||||
constructor(
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@IExtHostRpcService private readonly _extHostRpc: IExtHostRpcService,
|
||||
private readonly _notebooksAndEditors: ExtHostNotebookController,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
createNotebookEditorDecorationType(options: vscode.NotebookDecorationRenderOptions): vscode.NotebookEditorDecorationType {
|
||||
return new NotebookEditorDecorationType(this._extHostRpc.getProxy(MainContext.MainThreadNotebookEditors), options).value;
|
||||
}
|
||||
) { }
|
||||
|
||||
$acceptEditorPropertiesChanged(id: string, data: INotebookEditorPropertiesChangeData): void {
|
||||
this._logService.debug('ExtHostNotebook#$acceptEditorPropertiesChanged', id, data);
|
||||
|
|
|
@ -1675,16 +1675,6 @@ export namespace NotebookExclusiveDocumentPattern {
|
|||
}
|
||||
}
|
||||
|
||||
export namespace NotebookDecorationRenderOptions {
|
||||
export function from(options: vscode.NotebookDecorationRenderOptions): notebooks.INotebookDecorationRenderOptions {
|
||||
return {
|
||||
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
|
||||
borderColor: <string | types.ThemeColor>options.borderColor,
|
||||
top: options.top ? ThemableDecorationAttachmentRenderOptions.from(options.top) : undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export namespace NotebookStatusBarItem {
|
||||
export function from(item: vscode.NotebookCellStatusBarItem, commandsConverter: Command.ICommandsConverter, disposables: DisposableStore): notebooks.INotebookCellStatusBarItem {
|
||||
const command = typeof item.command === 'string' ? { title: '', command: item.command } : item.command;
|
||||
|
|
|
@ -591,16 +591,6 @@ export interface INotebookEditor {
|
|||
*/
|
||||
changeModelDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T | null;
|
||||
|
||||
/**
|
||||
* Set decoration key on cells in the range
|
||||
*/
|
||||
setEditorDecorations(key: string, range: ICellRange): void;
|
||||
|
||||
/**
|
||||
* Remove decoration key from the notebook editor
|
||||
*/
|
||||
removeEditorDecorations(key: string): void;
|
||||
|
||||
/**
|
||||
* Get a contribution of this editor.
|
||||
* @id Unique identifier of the contribution.
|
||||
|
|
|
@ -8,7 +8,6 @@ import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/com
|
|||
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
|
||||
import { INotebookEditor, INotebookEditorCreationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
export const INotebookEditorService = createDecorator<INotebookEditorService>('INotebookEditorWidgetService');
|
||||
|
||||
|
@ -27,8 +26,4 @@ export interface INotebookEditorService {
|
|||
removeNotebookEditor(editor: INotebookEditor): void;
|
||||
getNotebookEditor(editorId: string): INotebookEditor | undefined;
|
||||
listNotebookEditors(): readonly INotebookEditor[];
|
||||
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void;
|
||||
removeEditorDecorationType(key: string): void;
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import { isCompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbenc
|
|||
import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { INotebookEditor, INotebookEditorCreationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { GroupIdentifier } from 'vs/workbench/common/editor';
|
||||
|
||||
export class NotebookEditorWidgetService implements INotebookEditorService {
|
||||
|
@ -23,7 +22,6 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
|
|||
|
||||
private readonly _disposables = new DisposableStore();
|
||||
private readonly _notebookEditors = new Map<string, INotebookEditor>();
|
||||
private readonly _decorationOptionProviders = new Map<string, INotebookDecorationRenderOptions>();
|
||||
|
||||
private readonly _onNotebookEditorAdd = new Emitter<INotebookEditor>();
|
||||
private readonly _onNotebookEditorsRemove = new Emitter<INotebookEditor>();
|
||||
|
@ -185,21 +183,4 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
|
|||
listNotebookEditors(): readonly INotebookEditor[] {
|
||||
return [...this._notebookEditors].map(e => e[1]);
|
||||
}
|
||||
|
||||
// --- editor decorations
|
||||
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void {
|
||||
if (!this._decorationOptionProviders.has(key)) {
|
||||
this._decorationOptionProviders.set(key, options);
|
||||
}
|
||||
}
|
||||
|
||||
removeEditorDecorationType(key: string): void {
|
||||
this._decorationOptionProviders.delete(key);
|
||||
this.listNotebookEditors().forEach(editor => editor.removeEditorDecorations(key));
|
||||
}
|
||||
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined {
|
||||
return this._decorationOptionProviders.get(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ import { registerZIndex, ZIndex } from 'vs/platform/layout/browser/zIndexRegistr
|
|||
import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { contrastBorder, diffInserted, diffRemoved, editorBackground, errorForeground, focusBorder, foreground, iconForeground, listInactiveSelectionBackground, registerColor, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, textBlockQuoteBackground, textBlockQuoteBorder, textLinkActiveForeground, textLinkForeground, textPreformatForeground, toolbarHoverBackground, transparent } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { PANEL_BORDER, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
|
||||
import { debugIconStartForeground } from 'vs/workbench/contrib/debug/browser/debugColors';
|
||||
import { CellEditState, CellFindMatchWithIndex, CellFocusMode, CellLayoutContext, CellRevealType, IActiveNotebookEditorDelegate, IBaseCellEditorOptions, ICellOutputViewModel, ICellViewModel, ICommonCellInfo, IDisplayOutputLayoutUpdateRequest, IFocusNotebookCellOptions, IInsetRenderOutput, IModelDecorationsChangeAccessor, INotebookDeltaDecoration, INotebookEditor, INotebookEditorContribution, INotebookEditorContributionDescription, INotebookEditorCreationOptions, INotebookEditorDelegate, INotebookEditorMouseEvent, INotebookEditorOptions, INotebookEditorViewState, INotebookViewCellsUpdateEvent, INotebookWebviewMessage, RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
|
@ -66,7 +66,6 @@ import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/v
|
|||
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
|
||||
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl';
|
||||
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext';
|
||||
import { NotebookDecorationCSSRules, NotebookRefCountedStyleSheet } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorDecorations';
|
||||
import { NotebookEditorToolbar } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar';
|
||||
import { NotebookEditorContextKeys } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys';
|
||||
import { NotebookOverviewRuler } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookOverviewRuler';
|
||||
|
@ -346,7 +345,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
|
|||
@ILayoutService private readonly layoutService: ILayoutService,
|
||||
@IContextMenuService private readonly contextMenuService: IContextMenuService,
|
||||
@IMenuService private readonly menuService: IMenuService,
|
||||
@IThemeService private readonly themeService: IThemeService,
|
||||
@ITelemetryService private readonly telemetryService: ITelemetryService,
|
||||
@INotebookExecutionService private readonly notebookExecutionService: INotebookExecutionService,
|
||||
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
|
||||
|
@ -2078,61 +2076,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
|
|||
//#endregion
|
||||
|
||||
//#region Decorations
|
||||
private _editorStyleSheets = new Map<string, NotebookRefCountedStyleSheet>();
|
||||
private _decorationRules = new Map<string, NotebookDecorationCSSRules>();
|
||||
private _decortionKeyToIds = new Map<string, string[]>();
|
||||
|
||||
private _registerDecorationType(key: string) {
|
||||
const options = this.notebookEditorService.resolveEditorDecorationOptions(key);
|
||||
|
||||
if (options) {
|
||||
const styleElement = DOM.createStyleSheet(this._body);
|
||||
const styleSheet = new NotebookRefCountedStyleSheet({
|
||||
removeEditorStyleSheets: (key) => {
|
||||
this._editorStyleSheets.delete(key);
|
||||
}
|
||||
}, key, styleElement);
|
||||
this._editorStyleSheets.set(key, styleSheet);
|
||||
this._decorationRules.set(key, new NotebookDecorationCSSRules(this.themeService, styleSheet, {
|
||||
key,
|
||||
options,
|
||||
styleSheet
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
setEditorDecorations(key: string, range: ICellRange): void {
|
||||
if (!this.viewModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create css style for the decoration
|
||||
if (!this._editorStyleSheets.has(key)) {
|
||||
this._registerDecorationType(key);
|
||||
}
|
||||
|
||||
const decorationRule = this._decorationRules.get(key);
|
||||
if (!decorationRule) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingDecorations = this._decortionKeyToIds.get(key) || [];
|
||||
const newDecorations = this.viewModel.getCellsInRange(range).map(cell => ({
|
||||
handle: cell.handle,
|
||||
options: { className: decorationRule.className, outputClassName: decorationRule.className, topClassName: decorationRule.topClassName }
|
||||
}));
|
||||
|
||||
this._decortionKeyToIds.set(key, this.deltaCellDecorations(existingDecorations, newDecorations));
|
||||
}
|
||||
|
||||
removeEditorDecorations(key: string): void {
|
||||
if (this._decorationRules.has(key)) {
|
||||
this._decorationRules.get(key)?.dispose();
|
||||
}
|
||||
|
||||
const cellDecorations = this._decortionKeyToIds.get(key);
|
||||
this.deltaCellDecorations(cellDecorations || [], []);
|
||||
}
|
||||
|
||||
deltaCellDecorations(oldDecorations: string[], newDecorations: INotebookDeltaDecoration[]): string[] {
|
||||
const ret = this.viewModel?.deltaCellDecorations(oldDecorations, newDecorations) || [];
|
||||
|
|
|
@ -1,205 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { IContentDecorationRenderOptions, isThemeColor } from 'vs/editor/common/editorCommon';
|
||||
import { IColorTheme, IThemeService, ThemeColor } from 'vs/platform/theme/common/themeService';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { _CSS_MAP } from 'vs/editor/browser/services/abstractCodeEditorService';
|
||||
|
||||
export class NotebookRefCountedStyleSheet {
|
||||
private readonly _key: string;
|
||||
private readonly _styleSheet: HTMLStyleElement;
|
||||
private _refCount: number;
|
||||
|
||||
constructor(readonly widget: { removeEditorStyleSheets: (key: string) => void }, key: string, styleSheet: HTMLStyleElement) {
|
||||
this._key = key;
|
||||
this._styleSheet = styleSheet;
|
||||
this._refCount = 0;
|
||||
}
|
||||
|
||||
public ref(): void {
|
||||
this._refCount++;
|
||||
}
|
||||
|
||||
public unref(): void {
|
||||
this._refCount--;
|
||||
if (this._refCount === 0) {
|
||||
this._styleSheet.parentNode?.removeChild(this._styleSheet);
|
||||
this.widget.removeEditorStyleSheets(this._key);
|
||||
}
|
||||
}
|
||||
|
||||
public insertRule(rule: string, index?: number): void {
|
||||
const sheet = <CSSStyleSheet>this._styleSheet.sheet;
|
||||
sheet.insertRule(rule, index);
|
||||
}
|
||||
}
|
||||
|
||||
interface ProviderArguments {
|
||||
styleSheet: NotebookRefCountedStyleSheet;
|
||||
key: string;
|
||||
options: INotebookDecorationRenderOptions;
|
||||
}
|
||||
|
||||
export class NotebookDecorationCSSRules {
|
||||
private _theme: IColorTheme;
|
||||
private _className: string;
|
||||
private _topClassName: string;
|
||||
|
||||
get className() {
|
||||
return this._className;
|
||||
}
|
||||
|
||||
get topClassName() {
|
||||
return this._topClassName;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly _themeService: IThemeService,
|
||||
private readonly _styleSheet: NotebookRefCountedStyleSheet,
|
||||
private readonly _providerArgs: ProviderArguments
|
||||
) {
|
||||
this._styleSheet.ref();
|
||||
this._theme = this._themeService.getColorTheme();
|
||||
this._className = CSSNameHelper.getClassName(this._providerArgs.key, CellDecorationCSSRuleType.ClassName);
|
||||
this._topClassName = CSSNameHelper.getClassName(this._providerArgs.key, CellDecorationCSSRuleType.TopClassName);
|
||||
this._buildCSS();
|
||||
}
|
||||
|
||||
private _buildCSS() {
|
||||
if (this._providerArgs.options.backgroundColor) {
|
||||
const backgroundColor = this._resolveValue(this._providerArgs.options.backgroundColor);
|
||||
this._styleSheet.insertRule(`.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.code-cell-row.${this.className} .cell-focus-indicator,
|
||||
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.markdown-cell-row.${this.className} {
|
||||
background-color: ${backgroundColor} !important;
|
||||
}`);
|
||||
}
|
||||
|
||||
if (this._providerArgs.options.borderColor) {
|
||||
const borderColor = this._resolveValue(this._providerArgs.options.borderColor);
|
||||
|
||||
this._styleSheet.insertRule(`.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-focus-indicator-top:before,
|
||||
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-focus-indicator-bottom:before {
|
||||
border-color: ${borderColor} !important;
|
||||
}`);
|
||||
|
||||
this._styleSheet.insertRule(`
|
||||
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-focus-indicator-bottom:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
border-bottom: 1px solid ${borderColor};
|
||||
bottom: 0px;
|
||||
`);
|
||||
|
||||
this._styleSheet.insertRule(`
|
||||
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-focus-indicator-top:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
border-top: 1px solid ${borderColor};
|
||||
`);
|
||||
|
||||
// more specific rule for `.focused` can override existing rules
|
||||
this._styleSheet.insertRule(`.monaco-workbench .notebookOverlay .monaco-list:focus-within .monaco-list-row.focused.${this.className} .cell-focus-indicator-top:before,
|
||||
.monaco-workbench .notebookOverlay .monaco-list:focus-within .monaco-list-row.focused.${this.className} .cell-focus-indicator-bottom:before {
|
||||
border-color: ${borderColor} !important;
|
||||
}`);
|
||||
}
|
||||
|
||||
if (this._providerArgs.options.top) {
|
||||
const unthemedCSS = this._getCSSTextForModelDecorationContentClassName(this._providerArgs.options.top);
|
||||
this._styleSheet.insertRule(`.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-decoration .${this.topClassName} {
|
||||
height: 1rem;
|
||||
display: block;
|
||||
}`);
|
||||
|
||||
this._styleSheet.insertRule(`.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.${this.className} .cell-decoration .${this.topClassName}::before {
|
||||
display: block;
|
||||
${unthemedCSS}
|
||||
}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the CSS for decorations styled before or after content.
|
||||
*/
|
||||
private _getCSSTextForModelDecorationContentClassName(opts: IContentDecorationRenderOptions | undefined): string {
|
||||
if (!opts) {
|
||||
return '';
|
||||
}
|
||||
const cssTextArr: string[] = [];
|
||||
|
||||
if (typeof opts !== 'undefined') {
|
||||
this._collectBorderSettingsCSSText(opts, cssTextArr);
|
||||
if (typeof opts.contentIconPath !== 'undefined') {
|
||||
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, DOM.asCSSUrl(URI.revive(opts.contentIconPath))));
|
||||
}
|
||||
if (typeof opts.contentText === 'string') {
|
||||
const truncated = opts.contentText.match(/^.*$/m)![0]; // only take first line
|
||||
const escaped = truncated.replace(/['\\]/g, '\\$&');
|
||||
|
||||
cssTextArr.push(strings.format(_CSS_MAP.contentText, escaped));
|
||||
}
|
||||
this._collectCSSText(opts, ['fontStyle', 'fontWeight', 'textDecoration', 'color', 'opacity', 'backgroundColor', 'margin'], cssTextArr);
|
||||
if (this._collectCSSText(opts, ['width', 'height'], cssTextArr)) {
|
||||
cssTextArr.push('display:inline-block;');
|
||||
}
|
||||
}
|
||||
|
||||
return cssTextArr.join('');
|
||||
}
|
||||
|
||||
private _collectBorderSettingsCSSText(opts: any, cssTextArr: string[]): boolean {
|
||||
if (this._collectCSSText(opts, ['border', 'borderColor', 'borderRadius', 'borderSpacing', 'borderStyle', 'borderWidth'], cssTextArr)) {
|
||||
cssTextArr.push(strings.format('box-sizing: border-box;'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private _collectCSSText(opts: any, properties: string[], cssTextArr: string[]): boolean {
|
||||
const lenBefore = cssTextArr.length;
|
||||
for (const property of properties) {
|
||||
const value = this._resolveValue(opts[property]);
|
||||
if (typeof value === 'string') {
|
||||
cssTextArr.push(strings.format(_CSS_MAP[property], value));
|
||||
}
|
||||
}
|
||||
return cssTextArr.length !== lenBefore;
|
||||
}
|
||||
|
||||
private _resolveValue(value: string | ThemeColor): string {
|
||||
if (isThemeColor(value)) {
|
||||
const color = this._theme.getColor(value.id);
|
||||
if (color) {
|
||||
return color.toString();
|
||||
}
|
||||
return 'transparent';
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._styleSheet.unref();
|
||||
}
|
||||
}
|
||||
|
||||
const enum CellDecorationCSSRuleType {
|
||||
ClassName = 0,
|
||||
TopClassName = 0,
|
||||
}
|
||||
|
||||
class CSSNameHelper {
|
||||
|
||||
public static getClassName(key: string, type: CellDecorationCSSRuleType): string {
|
||||
return 'nb-' + key + '-' + type;
|
||||
}
|
||||
}
|
|
@ -924,12 +924,6 @@ export const enum CellStatusbarAlignment {
|
|||
Right = 2
|
||||
}
|
||||
|
||||
export interface INotebookDecorationRenderOptions {
|
||||
backgroundColor?: string | ThemeColor;
|
||||
borderColor?: string | ThemeColor;
|
||||
top?: editorCommon.IContentDecorationRenderOptions;
|
||||
}
|
||||
|
||||
export class NotebookWorkingCopyTypeIdentifier {
|
||||
|
||||
private static _prefix = 'notebook/';
|
||||
|
|
|
@ -37,7 +37,6 @@ export const allApiProposals = Object.freeze({
|
|||
notebookDebugOptions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookDebugOptions.d.ts',
|
||||
notebookDeprecated: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookDeprecated.d.ts',
|
||||
notebookEditor: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookEditor.d.ts',
|
||||
notebookEditorDecorationType: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookEditorDecorationType.d.ts',
|
||||
notebookEditorEdit: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookEditorEdit.d.ts',
|
||||
notebookKernelSource: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookKernelSource.d.ts',
|
||||
notebookLiveShare: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookLiveShare.d.ts',
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/106744
|
||||
|
||||
export interface NotebookEditor {
|
||||
setDecorations(decorationType: NotebookEditorDecorationType, range: NotebookRange): void;
|
||||
}
|
||||
|
||||
export interface NotebookDecorationRenderOptions {
|
||||
backgroundColor?: string | ThemeColor;
|
||||
borderColor?: string | ThemeColor;
|
||||
top?: ThemableDecorationAttachmentRenderOptions;
|
||||
}
|
||||
|
||||
export interface NotebookEditorDecorationType {
|
||||
readonly key: string;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export namespace notebooks {
|
||||
export function createNotebookEditorDecorationType(options: NotebookDecorationRenderOptions): NotebookEditorDecorationType;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue