diff --git a/src/vs/editor/browser/view/view.ts b/src/vs/editor/browser/view/view.ts index d9d0ece0237..e4f0378c7fe 100644 --- a/src/vs/editor/browser/view/view.ts +++ b/src/vs/editor/browser/view/view.ts @@ -47,7 +47,7 @@ import * as viewEvents from 'vs/editor/common/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { ViewEventHandler } from 'vs/editor/common/viewEventHandler'; import { IViewModel } from 'vs/editor/common/viewModel'; -import { IThemeService, getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; +import { getThemeTypeSelector, IColorTheme } from 'vs/platform/theme/common/themeService'; import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { PointerHandlerLastRenderData } from 'vs/editor/browser/controller/mouseTarget'; @@ -92,7 +92,7 @@ export class View extends ViewEventHandler { constructor( commandDelegate: ICommandDelegate, configuration: IEditorConfiguration, - themeService: IThemeService, + colorTheme: IColorTheme, model: IViewModel, userInputEvents: ViewUserInputEvents, overflowWidgetsDomNode: HTMLElement | undefined @@ -104,17 +104,11 @@ export class View extends ViewEventHandler { const viewController = new ViewController(configuration, model, userInputEvents, commandDelegate); // The view context is passed on to most classes (basically to reduce param. counts in ctors) - this._context = new ViewContext(configuration, themeService.getColorTheme(), model); + this._context = new ViewContext(configuration, colorTheme, model); // Ensure the view is the first event handler in order to update the layout this._context.addEventHandler(this); - this._register(themeService.onDidColorThemeChange(theme => { - this._context.theme.update(theme); - this._context.viewModel.onDidColorThemeChange(); - this.render(true, false); - })); - this._viewParts = []; // Keyboard handler @@ -316,6 +310,7 @@ export class View extends ViewEventHandler { return false; } public override onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean { + this._context.theme.update(e.theme); this.domNode.setClassName(this._getEditorClassName()); return false; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index a877bf991ae..d9a031371a5 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1542,7 +1542,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE DOMLineBreaksComputerFactory.create(), MonospaceLineBreaksComputerFactory.create(this._configuration.options), (callback) => dom.scheduleAtNextAnimationFrame(callback), - this.languageConfigurationService + this.languageConfigurationService, + this._themeService ); listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e))); @@ -1706,7 +1707,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE const view = new View( commandDelegate, this._configuration, - this._themeService, + this._themeService.getColorTheme(), viewModel, viewUserInputEvents, this._overflowWidgetsDomNode diff --git a/src/vs/editor/common/viewEvents.ts b/src/vs/editor/common/viewEvents.ts index 06b47e935df..13a6696c363 100644 --- a/src/vs/editor/common/viewEvents.ts +++ b/src/vs/editor/common/viewEvents.ts @@ -9,6 +9,7 @@ import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { ScrollType } from 'vs/editor/common/editorCommon'; import { IModelDecorationsChangedEvent } from 'vs/editor/common/textModelEvents'; +import { IColorTheme } from 'vs/platform/theme/common/themeService'; export const enum ViewEventType { ViewCompositionStart, @@ -256,6 +257,10 @@ export class ViewScrollChangedEvent { export class ViewThemeChangedEvent { public readonly type = ViewEventType.ViewThemeChanged; + + constructor( + public readonly theme: IColorTheme + ) { } } export class ViewTokensChangedEvent { diff --git a/src/vs/editor/common/viewModel.ts b/src/vs/editor/common/viewModel.ts index 76440f2aee3..a78cbd679d9 100644 --- a/src/vs/editor/common/viewModel.ts +++ b/src/vs/editor/common/viewModel.ts @@ -41,7 +41,6 @@ export interface IViewModel extends ICursorSimpleModel { setHasFocus(hasFocus: boolean): void; onCompositionStart(): void; onCompositionEnd(): void; - onDidColorThemeChange(): void; getDecorationsInViewport(visibleRange: Range): ViewModelDecoration[]; getViewLineRenderingData(visibleRange: Range, lineNumber: number): ViewLineRenderingData; diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 09c950eb58e..35a5f20993d 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -38,6 +38,7 @@ import { ICoordinatesConverter, IViewModel, MinimapLinesRenderingData, OverviewR import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecorations'; import { FocusChangedEvent, OutgoingViewModelEvent, ReadOnlyEditAttemptEvent, ScrollChangedEvent, ViewModelEventDispatcher, ViewModelEventsCollector, ViewZonesChangedEvent } from 'vs/editor/common/viewModelEventDispatcher'; import { IViewModelLines, ViewModelLinesFromModelAsIs, ViewModelLinesFromProjectedModel } from 'vs/editor/common/viewModel/viewModelLines'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; const USE_IDENTITY_LINES_COLLECTION = true; @@ -68,7 +69,8 @@ export class ViewModel extends Disposable implements IViewModel { domLineBreaksComputerFactory: ILineBreaksComputerFactory, monospaceLineBreaksComputerFactory: ILineBreaksComputerFactory, scheduleAtNextAnimationFrame: (callback: () => void) => IDisposable, - private readonly languageConfigurationService: ILanguageConfigurationService + private readonly languageConfigurationService: ILanguageConfigurationService, + private readonly _themeService: IThemeService, ) { super(); @@ -147,6 +149,10 @@ export class ViewModel extends Disposable implements IViewModel { this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewTokensColorsChangedEvent()); })); + this._register(this._themeService.onDidColorThemeChange((theme) => { + this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewThemeChangedEvent(theme)); + })); + this._updateConfigurationViewLineCountNow(); } @@ -207,10 +213,6 @@ export class ViewModel extends Disposable implements IViewModel { this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewCompositionEndEvent()); } - public onDidColorThemeChange(): void { - this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewThemeChangedEvent()); - } - private _onConfigurationChanged(eventsCollector: ViewModelEventsCollector, e: ConfigurationChangedEvent): void { // We might need to restore the current centered view range, so save it (if available) diff --git a/src/vs/editor/test/browser/viewModel/testViewModel.ts b/src/vs/editor/test/browser/viewModel/testViewModel.ts index b8317241bb7..28fb4ac5e19 100644 --- a/src/vs/editor/test/browser/viewModel/testViewModel.ts +++ b/src/vs/editor/test/browser/viewModel/testViewModel.ts @@ -10,6 +10,7 @@ import { TestConfiguration } from 'vs/editor/test/browser/config/testConfigurati import { MonospaceLineBreaksComputerFactory } from 'vs/editor/common/viewModel/monospaceLineBreaksComputer'; import { createTextModel } from 'vs/editor/test/common/testTextModel'; import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService'; +import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; export function testViewModel(text: string[], options: IEditorOptions, callback: (viewModel: ViewModel, model: TextModel) => void): void { const EDITOR_ID = 1; @@ -17,7 +18,7 @@ export function testViewModel(text: string[], options: IEditorOptions, callback: const configuration = new TestConfiguration(options); const model = createTextModel(text.join('\n')); const monospaceLineBreaksComputerFactory = MonospaceLineBreaksComputerFactory.create(configuration.options); - const viewModel = new ViewModel(EDITOR_ID, configuration, model, monospaceLineBreaksComputerFactory, monospaceLineBreaksComputerFactory, null!, new TestLanguageConfigurationService()); + const viewModel = new ViewModel(EDITOR_ID, configuration, model, monospaceLineBreaksComputerFactory, monospaceLineBreaksComputerFactory, null!, new TestLanguageConfigurationService(), new TestThemeService()); callback(viewModel, model);