Selection foreground for canvas (circular dep issue)

This commit is contained in:
Daniel Imms
2022-05-16 15:17:03 -07:00
parent eb96187801
commit f2b90d690f
5 changed files with 26 additions and 11 deletions
+10 -1
View File
@@ -18,6 +18,7 @@ import { isPowerlineGlyph, throwIfFalsy } from 'browser/renderer/RendererUtils';
import { channels, color, rgba } from 'common/Color';
import { removeElementFromParent } from 'browser/Dom';
import { tryDrawCustomChar } from 'browser/renderer/CustomGlyphs';
import { ISelectionService } from 'browser/services/Services';
export abstract class BaseRenderLayer implements IRenderLayer {
private _canvas: HTMLCanvasElement;
@@ -53,7 +54,8 @@ export abstract class BaseRenderLayer implements IRenderLayer {
private _rendererId: number,
protected readonly _bufferService: IBufferService,
protected readonly _optionsService: IOptionsService,
protected readonly _decorationService: IDecorationService
protected readonly _decorationService: IDecorationService,
protected readonly _selectionService: ISelectionService
) {
this._canvas = document.createElement('canvas');
this._canvas.classList.add(`xterm-${id}-layer`);
@@ -457,6 +459,13 @@ export abstract class BaseRenderLayer implements IRenderLayer {
isTop = d.options.layer === 'top';
}
// Apply selection foreground if applicable
if (!isTop) {
if (this._colors.selectionForeground && this._selectionService.isCellInSelection(x, y)) {
fgOverride = this._colors.selectionForeground.rgba;
}
}
if (!bgOverride && !fgOverride && (this._optionsService.rawOptions.minimumContrastRatio === 1 || isPowerlineGlyph(cell.getCode()))) {
return undefined;
}
+4 -3
View File
@@ -10,7 +10,7 @@ import { CellData } from 'common/buffer/CellData';
import { IColorSet } from 'browser/Types';
import { IBufferService, IOptionsService, ICoreService, IDecorationService } from 'common/services/Services';
import { IEventEmitter } from 'common/EventEmitter';
import { ICoreBrowserService } from 'browser/services/Services';
import { ICoreBrowserService, ISelectionService } from 'browser/services/Services';
interface ICursorState {
x: number;
@@ -41,9 +41,10 @@ export class CursorRenderLayer extends BaseRenderLayer {
@IOptionsService optionsService: IOptionsService,
@ICoreService private readonly _coreService: ICoreService,
@ICoreBrowserService private readonly _coreBrowserService: ICoreBrowserService,
@IDecorationService decorationService: IDecorationService
@IDecorationService decorationService: IDecorationService,
@ISelectionService selectionService: ISelectionService
) {
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
this._state = {
x: 0,
y: 0,
+4 -2
View File
@@ -9,6 +9,7 @@ import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
import { is256Color } from 'browser/renderer/atlas/CharAtlasUtils';
import { IColorSet, ILinkifierEvent, ILinkifier, ILinkifier2 } from 'browser/Types';
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ISelectionService } from 'browser/services/Services';
export class LinkRenderLayer extends BaseRenderLayer {
private _state: ILinkifierEvent | undefined;
@@ -22,9 +23,10 @@ export class LinkRenderLayer extends BaseRenderLayer {
linkifier2: ILinkifier2,
@IBufferService bufferService: IBufferService,
@IOptionsService optionsService: IOptionsService,
@IDecorationService decorationService: IDecorationService
@IDecorationService decorationService: IDecorationService,
@ISelectionService selectionService: ISelectionService
) {
super(container, 'link', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
super(container, 'link', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
linkifier.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
linkifier.onHideLinkUnderline(e => this._onHideLinkUnderline(e));
+4 -2
View File
@@ -7,6 +7,7 @@ import { IRenderDimensions } from 'browser/renderer/Types';
import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer';
import { IColorSet } from 'browser/Types';
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ISelectionService } from 'browser/services/Services';
interface ISelectionState {
start?: [number, number];
@@ -25,9 +26,10 @@ export class SelectionRenderLayer extends BaseRenderLayer {
rendererId: number,
@IBufferService bufferService: IBufferService,
@IOptionsService optionsService: IOptionsService,
@IDecorationService decorationService: IDecorationService
@IDecorationService decorationService: IDecorationService,
@ISelectionService selectionService: ISelectionService
) {
super(container, 'selection', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
super(container, 'selection', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
this._clearState();
}
+4 -3
View File
@@ -12,7 +12,7 @@ import { NULL_CELL_CODE, Content } from 'common/buffer/Constants';
import { IColorSet } from 'browser/Types';
import { CellData } from 'common/buffer/CellData';
import { IOptionsService, IBufferService, IDecorationService } from 'common/services/Services';
import { ICharacterJoinerService } from 'browser/services/Services';
import { ICharacterJoinerService, ISelectionService } from 'browser/services/Services';
import { JoinedCellData } from 'browser/services/CharacterJoinerService';
/**
@@ -38,9 +38,10 @@ export class TextRenderLayer extends BaseRenderLayer {
@IBufferService bufferService: IBufferService,
@IOptionsService optionsService: IOptionsService,
@ICharacterJoinerService private readonly _characterJoinerService: ICharacterJoinerService,
@IDecorationService decorationService: IDecorationService
@IDecorationService decorationService: IDecorationService,
@ISelectionService selectionService: ISelectionService
) {
super(container, 'text', zIndex, alpha, colors, rendererId, bufferService, optionsService, decorationService);
super(container, 'text', zIndex, alpha, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
this._state = new GridCache<CharData>();
}