Fix circular dependency mouseservice <-> renderservice
This commit is contained in:
@@ -18,7 +18,6 @@ import { isPowerlineGlyph, throwIfFalsy } from 'browser/renderer/RendererUtils';
|
|||||||
import { channels, color, rgba } from 'common/Color';
|
import { channels, color, rgba } from 'common/Color';
|
||||||
import { removeElementFromParent } from 'browser/Dom';
|
import { removeElementFromParent } from 'browser/Dom';
|
||||||
import { tryDrawCustomChar } from 'browser/renderer/CustomGlyphs';
|
import { tryDrawCustomChar } from 'browser/renderer/CustomGlyphs';
|
||||||
import { ISelectionService } from 'browser/services/Services';
|
|
||||||
|
|
||||||
export abstract class BaseRenderLayer implements IRenderLayer {
|
export abstract class BaseRenderLayer implements IRenderLayer {
|
||||||
private _canvas: HTMLCanvasElement;
|
private _canvas: HTMLCanvasElement;
|
||||||
@@ -30,6 +29,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
private _scaledCharLeft: number = 0;
|
private _scaledCharLeft: number = 0;
|
||||||
private _scaledCharTop: number = 0;
|
private _scaledCharTop: number = 0;
|
||||||
|
|
||||||
|
private _selectionStart: [number, number] | undefined;
|
||||||
|
private _selectionEnd: [number, number] | undefined;
|
||||||
|
private _columnSelectMode: boolean = false;
|
||||||
|
|
||||||
protected _charAtlas: BaseCharAtlas | undefined;
|
protected _charAtlas: BaseCharAtlas | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,8 +57,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
private _rendererId: number,
|
private _rendererId: number,
|
||||||
protected readonly _bufferService: IBufferService,
|
protected readonly _bufferService: IBufferService,
|
||||||
protected readonly _optionsService: IOptionsService,
|
protected readonly _optionsService: IOptionsService,
|
||||||
protected readonly _decorationService: IDecorationService,
|
protected readonly _decorationService: IDecorationService
|
||||||
protected readonly _selectionService: ISelectionService
|
|
||||||
) {
|
) {
|
||||||
this._canvas = document.createElement('canvas');
|
this._canvas = document.createElement('canvas');
|
||||||
this._canvas.classList.add(`xterm-${id}-layer`);
|
this._canvas.classList.add(`xterm-${id}-layer`);
|
||||||
@@ -82,7 +84,12 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
public onFocus(): void {}
|
public onFocus(): void {}
|
||||||
public onCursorMove(): void {}
|
public onCursorMove(): void {}
|
||||||
public onGridChanged(startRow: number, endRow: number): void {}
|
public onGridChanged(startRow: number, endRow: number): void {}
|
||||||
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {}
|
|
||||||
|
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
|
||||||
|
this._selectionStart = start;
|
||||||
|
this._selectionEnd = end;
|
||||||
|
this._columnSelectMode = columnSelectMode;
|
||||||
|
}
|
||||||
|
|
||||||
public setColors(colorSet: IColorSet): void {
|
public setColors(colorSet: IColorSet): void {
|
||||||
this._refreshCharAtlas(colorSet);
|
this._refreshCharAtlas(colorSet);
|
||||||
@@ -461,7 +468,7 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
|
|
||||||
// Apply selection foreground if applicable
|
// Apply selection foreground if applicable
|
||||||
if (!isTop) {
|
if (!isTop) {
|
||||||
if (this._colors.selectionForeground && this._selectionService.isCellInSelection(x, y)) {
|
if (this._colors.selectionForeground && this._isCellInSelection(x, y)) {
|
||||||
fgOverride = this._colors.selectionForeground.rgba;
|
fgOverride = this._colors.selectionForeground.rgba;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -555,5 +562,17 @@ export abstract class BaseRenderLayer implements IRenderLayer {
|
|||||||
return this._colors.foreground.rgba;
|
return this._colors.foreground.rgba;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _isCellInSelection(x: number, y: number): boolean {
|
||||||
|
const start = this._selectionStart;
|
||||||
|
const end = this._selectionEnd;
|
||||||
|
if (!start || !end) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (y > start[1] && y < end[1]) ||
|
||||||
|
(start[1] === end[1] && y === start[1] && x >= start[0] && x < end[0]) ||
|
||||||
|
(start[1] < end[1] && y === end[1] && x < end[0]) ||
|
||||||
|
(start[1] < end[1] && y === start[1] && x >= start[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { CellData } from 'common/buffer/CellData';
|
|||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
import { IBufferService, IOptionsService, ICoreService, IDecorationService } from 'common/services/Services';
|
import { IBufferService, IOptionsService, ICoreService, IDecorationService } from 'common/services/Services';
|
||||||
import { IEventEmitter } from 'common/EventEmitter';
|
import { IEventEmitter } from 'common/EventEmitter';
|
||||||
import { ICoreBrowserService, ISelectionService } from 'browser/services/Services';
|
import { ICoreBrowserService } from 'browser/services/Services';
|
||||||
|
|
||||||
interface ICursorState {
|
interface ICursorState {
|
||||||
x: number;
|
x: number;
|
||||||
@@ -41,10 +41,9 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
@IOptionsService optionsService: IOptionsService,
|
@IOptionsService optionsService: IOptionsService,
|
||||||
@ICoreService private readonly _coreService: ICoreService,
|
@ICoreService private readonly _coreService: ICoreService,
|
||||||
@ICoreBrowserService private readonly _coreBrowserService: ICoreBrowserService,
|
@ICoreBrowserService private readonly _coreBrowserService: ICoreBrowserService,
|
||||||
@IDecorationService decorationService: IDecorationService,
|
@IDecorationService decorationService: IDecorationService
|
||||||
@ISelectionService selectionService: ISelectionService
|
|
||||||
) {
|
) {
|
||||||
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
|
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
|
||||||
this._state = {
|
this._state = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
|
|||||||
import { is256Color } from 'browser/renderer/atlas/CharAtlasUtils';
|
import { is256Color } from 'browser/renderer/atlas/CharAtlasUtils';
|
||||||
import { IColorSet, ILinkifierEvent, ILinkifier, ILinkifier2 } from 'browser/Types';
|
import { IColorSet, ILinkifierEvent, ILinkifier, ILinkifier2 } from 'browser/Types';
|
||||||
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||||
import { ISelectionService } from 'browser/services/Services';
|
|
||||||
|
|
||||||
export class LinkRenderLayer extends BaseRenderLayer {
|
export class LinkRenderLayer extends BaseRenderLayer {
|
||||||
private _state: ILinkifierEvent | undefined;
|
private _state: ILinkifierEvent | undefined;
|
||||||
@@ -23,10 +22,9 @@ export class LinkRenderLayer extends BaseRenderLayer {
|
|||||||
linkifier2: ILinkifier2,
|
linkifier2: ILinkifier2,
|
||||||
@IBufferService bufferService: IBufferService,
|
@IBufferService bufferService: IBufferService,
|
||||||
@IOptionsService optionsService: IOptionsService,
|
@IOptionsService optionsService: IOptionsService,
|
||||||
@IDecorationService decorationService: IDecorationService,
|
@IDecorationService decorationService: IDecorationService
|
||||||
@ISelectionService selectionService: ISelectionService
|
|
||||||
) {
|
) {
|
||||||
super(container, 'link', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
|
super(container, 'link', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
|
||||||
linkifier.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
|
linkifier.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
|
||||||
linkifier.onHideLinkUnderline(e => this._onHideLinkUnderline(e));
|
linkifier.onHideLinkUnderline(e => this._onHideLinkUnderline(e));
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ export class Renderer extends Disposable implements IRenderer {
|
|||||||
|
|
||||||
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
|
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
|
||||||
this._runOperation(l => l.onSelectionChanged(start, end, columnSelectMode));
|
this._runOperation(l => l.onSelectionChanged(start, end, columnSelectMode));
|
||||||
|
// Selection foreground requires a full re-render
|
||||||
|
if (this._colors.selectionForeground) {
|
||||||
|
this._onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public onCursorMove(): void {
|
public onCursorMove(): void {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { IRenderDimensions } from 'browser/renderer/Types';
|
|||||||
import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer';
|
import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
|
||||||
import { ISelectionService } from 'browser/services/Services';
|
|
||||||
|
|
||||||
interface ISelectionState {
|
interface ISelectionState {
|
||||||
start?: [number, number];
|
start?: [number, number];
|
||||||
@@ -26,10 +25,9 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
rendererId: number,
|
rendererId: number,
|
||||||
@IBufferService bufferService: IBufferService,
|
@IBufferService bufferService: IBufferService,
|
||||||
@IOptionsService optionsService: IOptionsService,
|
@IOptionsService optionsService: IOptionsService,
|
||||||
@IDecorationService decorationService: IDecorationService,
|
@IDecorationService decorationService: IDecorationService
|
||||||
@ISelectionService selectionService: ISelectionService
|
|
||||||
) {
|
) {
|
||||||
super(container, 'selection', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
|
super(container, 'selection', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
|
||||||
this._clearState();
|
this._clearState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +54,8 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void {
|
public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void {
|
||||||
|
super.onSelectionChanged(start, end, columnSelectMode);
|
||||||
|
|
||||||
// Selection has not changed
|
// Selection has not changed
|
||||||
if (!this._didStateChange(start, end, columnSelectMode, this._bufferService.buffer.ydisp)) {
|
if (!this._didStateChange(start, end, columnSelectMode, this._bufferService.buffer.ydisp)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { NULL_CELL_CODE, Content } from 'common/buffer/Constants';
|
|||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet } from 'browser/Types';
|
||||||
import { CellData } from 'common/buffer/CellData';
|
import { CellData } from 'common/buffer/CellData';
|
||||||
import { IOptionsService, IBufferService, IDecorationService } from 'common/services/Services';
|
import { IOptionsService, IBufferService, IDecorationService } from 'common/services/Services';
|
||||||
import { ICharacterJoinerService, ISelectionService } from 'browser/services/Services';
|
import { ICharacterJoinerService } from 'browser/services/Services';
|
||||||
import { JoinedCellData } from 'browser/services/CharacterJoinerService';
|
import { JoinedCellData } from 'browser/services/CharacterJoinerService';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,10 +38,9 @@ export class TextRenderLayer extends BaseRenderLayer {
|
|||||||
@IBufferService bufferService: IBufferService,
|
@IBufferService bufferService: IBufferService,
|
||||||
@IOptionsService optionsService: IOptionsService,
|
@IOptionsService optionsService: IOptionsService,
|
||||||
@ICharacterJoinerService private readonly _characterJoinerService: ICharacterJoinerService,
|
@ICharacterJoinerService private readonly _characterJoinerService: ICharacterJoinerService,
|
||||||
@IDecorationService decorationService: IDecorationService,
|
@IDecorationService decorationService: IDecorationService
|
||||||
@ISelectionService selectionService: ISelectionService
|
|
||||||
) {
|
) {
|
||||||
super(container, 'text', zIndex, alpha, colors, rendererId, bufferService, optionsService, decorationService, selectionService);
|
super(container, 'text', zIndex, alpha, colors, rendererId, bufferService, optionsService, decorationService);
|
||||||
this._state = new GridCache<CharData>();
|
this._state = new GridCache<CharData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user