Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0befb9c

Browse files
authored
Merge pull request#3965 from Tyriar/inactiveSelection
Inactive selection background support
2 parentsa2e07de +ff33834 commit0befb9c

File tree

15 files changed

+89
-39
lines changed

15 files changed

+89
-39
lines changed

‎addons/xterm-addon-canvas/src/CanvasRenderer.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { LinkRenderLayer } from './LinkRenderLayer';
1212
import{Disposable}from'common/Lifecycle';
1313
import{IColorSet,ILinkifier2}from'browser/Types';
1414
import{ICharacterJoinerService,ICharSizeService,ICoreBrowserService}from'browser/services/Services';
15-
import{IBufferService,IOptionsService,IInstantiationService,IDecorationService,ICoreService}from'common/services/Services';
15+
import{IBufferService,IOptionsService,IDecorationService,ICoreService}from'common/services/Services';
1616
import{removeTerminalFromCache}from'./atlas/CharAtlasCache';
1717
import{EventEmitter,IEvent}from'common/EventEmitter';
1818
import{observeDevicePixelDimensions}from'browser/renderer/DevicePixelObserver';
@@ -46,7 +46,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
4646
constallowTransparency=this._optionsService.rawOptions.allowTransparency;
4747
this._renderLayers=[
4848
newTextRenderLayer(this._screenElement,0,this._colors,allowTransparency,this._id,this._bufferService,this._optionsService,characterJoinerService,decorationService),
49-
newSelectionRenderLayer(this._screenElement,1,this._colors,this._id,this._bufferService,this._optionsService,decorationService),
49+
newSelectionRenderLayer(this._screenElement,1,this._colors,this._id,this._bufferService,coreBrowserService,decorationService,this._optionsService),
5050
newLinkRenderLayer(this._screenElement,2,this._colors,this._id,linkifier2,this._bufferService,this._optionsService,decorationService),
5151
newCursorRenderLayer(this._screenElement,3,this._colors,this._id,this._onRequestRedraw,this._bufferService,this._optionsService,coreService,coreBrowserService,decorationService)
5252
];

‎addons/xterm-addon-canvas/src/CursorRenderLayer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
3636
zIndex:number,
3737
colors:IColorSet,
3838
rendererId:number,
39-
private_onRequestRedraw:IEventEmitter<IRequestRedrawEvent>,
39+
privatereadonly_onRequestRedraw:IEventEmitter<IRequestRedrawEvent>,
4040
bufferService:IBufferService,
4141
optionsService:IOptionsService,
4242
privatereadonly_coreService:ICoreService,

‎addons/xterm-addon-canvas/src/SelectionRenderLayer.ts‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
*@license MIT
44
*/
55

6-
import{IRenderDimensions}from'browser/renderer/Types';
6+
import{IRenderDimensions,IRequestRedrawEvent}from'browser/renderer/Types';
77
import{BaseRenderLayer}from'./BaseRenderLayer';
88
import{IColorSet}from'browser/Types';
99
import{IBufferService,IDecorationService,IOptionsService}from'common/services/Services';
10+
import{ICoreBrowserService}from'browser/services/Services';
11+
import{IEventEmitter}from'common/EventEmitter';
1012

1113
interfaceISelectionState{
1214
start?:[number,number];
@@ -24,8 +26,9 @@ export class SelectionRenderLayer extends BaseRenderLayer {
2426
colors:IColorSet,
2527
rendererId:number,
2628
bufferService:IBufferService,
27-
optionsService:IOptionsService,
28-
decorationService:IDecorationService
29+
privatereadonly_coreBrowserService:ICoreBrowserService,
30+
decorationService:IDecorationService,
31+
optionsService:IOptionsService
2932
){
3033
super(container,'selection',zIndex,true,colors,rendererId,bufferService,optionsService,decorationService);
3134
this._clearState();
@@ -45,7 +48,7 @@ export class SelectionRenderLayer extends BaseRenderLayer {
4548
// On resize use the base render layer's cached selection values since resize clears _state
4649
// inside reset.
4750
if(this._selectionStart&&this._selectionEnd){
48-
this.onSelectionChanged(this._selectionStart,this._selectionEnd,this._columnSelectMode);
51+
this._redrawSelection(this._selectionStart,this._selectionEnd,this._columnSelectMode);
4952
}
5053
}
5154

@@ -56,9 +59,22 @@ export class SelectionRenderLayer extends BaseRenderLayer {
5659
}
5760
}
5861

62+
publiconBlur():void{
63+
this.reset();
64+
this._redrawSelection(this._selectionStart,this._selectionEnd,this._columnSelectMode);
65+
}
66+
67+
publiconFocus():void{
68+
this.reset();
69+
this._redrawSelection(this._selectionStart,this._selectionEnd,this._columnSelectMode);
70+
}
71+
5972
publiconSelectionChanged(start:[number,number]|undefined,end:[number,number]|undefined,columnSelectMode:boolean):void{
6073
super.onSelectionChanged(start,end,columnSelectMode);
74+
this._redrawSelection(start,end,columnSelectMode);
75+
}
6176

77+
private_redrawSelection(start:[number,number]|undefined,end:[number,number]|undefined,columnSelectMode:boolean):void{
6278
// Selection has not changed
6379
if(!this._didStateChange(start,end,columnSelectMode,this._bufferService.buffer.ydisp)){
6480
return;
@@ -85,7 +101,9 @@ export class SelectionRenderLayer extends BaseRenderLayer {
85101
return;
86102
}
87103

88-
this._ctx.fillStyle=this._colors.selectionBackgroundTransparent.css;
104+
this._ctx.fillStyle=(this._coreBrowserService.isFocused
105+
?this._colors.selectionBackgroundTransparent
106+
:this._colors.selectionInactiveBackgroundTransparent).css;
89107

90108
if(columnSelectMode){
91109
conststartCol=start[0];

‎addons/xterm-addon-webgl/src/WebglAddon.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import{Terminal,ITerminalAddon,IEvent}from'xterm';
77
import{WebglRenderer}from'./WebglRenderer';
8-
import{ICharacterJoinerService,IRenderService}from'browser/services/Services';
8+
import{ICharacterJoinerService,ICoreBrowserService,IRenderService}from'browser/services/Services';
99
import{IColorSet}from'browser/Types';
1010
import{EventEmitter}from'common/EventEmitter';
1111
import{isSafari}from'common/Platform';
12-
import{IDecorationService}from'common/services/Services';
12+
import{ICoreService,IDecorationService}from'common/services/Services';
1313

1414
exportclassWebglAddonimplementsITerminalAddon{
1515
private_terminal?:Terminal;
@@ -31,9 +31,11 @@ export class WebglAddon implements ITerminalAddon {
3131
this._terminal=terminal;
3232
constrenderService:IRenderService=(terminalasany)._core._renderService;
3333
constcharacterJoinerService:ICharacterJoinerService=(terminalasany)._core._characterJoinerService;
34+
constcoreBrowserService:ICoreBrowserService=(terminalasany)._core._coreBrowserService;
35+
constcoreService:ICoreService=(terminalasany)._core.coreService;
3436
constdecorationService:IDecorationService=(terminalasany)._core._decorationService;
3537
constcolors:IColorSet=(terminalasany)._core._colorManager.colors;
36-
this._renderer=newWebglRenderer(terminal,colors,characterJoinerService,decorationService,this._preserveDrawingBuffer);
38+
this._renderer=newWebglRenderer(terminal,colors,characterJoinerService,coreBrowserService,coreService,decorationService,this._preserveDrawingBuffer);
3739
this._renderer.onContextLoss(()=>this._onContextLoss.fire());
3840
renderService.setRenderer(this._renderer);
3941
}

‎addons/xterm-addon-webgl/src/WebglRenderer.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { ITerminal, IColorSet } from 'browser/Types';
2121
import{EventEmitter}from'common/EventEmitter';
2222
import{CellData}from'common/buffer/CellData';
2323
import{addDisposableDomListener}from'browser/Lifecycle';
24-
import{ICharacterJoinerService}from'browser/services/Services';
24+
import{ICharacterJoinerService,ICoreBrowserService}from'browser/services/Services';
2525
import{CharData,ICellData}from'common/Types';
2626
import{AttributeData}from'common/buffer/AttributeData';
27-
import{IDecorationService}from'common/services/Services';
27+
import{ICoreService,IDecorationService}from'common/services/Services';
2828
import{color,rgbaasrgbaNs}from'common/Color';
2929

3030
exportclassWebglRendererextendsDisposableimplementsIRenderer{
@@ -56,6 +56,8 @@ export class WebglRenderer extends Disposable implements IRenderer {
5656
private_terminal:Terminal,
5757
private_colors:IColorSet,
5858
privatereadonly_characterJoinerService:ICharacterJoinerService,
59+
privatereadonly_coreBrowserService:ICoreBrowserService,
60+
coreService:ICoreService,
5961
privatereadonly_decorationService:IDecorationService,
6062
preserveDrawingBuffer?:boolean
6163
){
@@ -65,7 +67,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
6567

6668
this._renderLayers=[
6769
newLinkRenderLayer(this._core.screenElement!,2,this._colors,this._core),
68-
newCursorRenderLayer(_terminal,this._core.screenElement!,3,this._colors,this._core,this._onRequestRedraw)
70+
newCursorRenderLayer(_terminal,this._core.screenElement!,3,this._colors,this._onRequestRedraw,this._coreBrowserService,coreService)
6971
];
7072
this.dimensions={
7173
scaledCharWidth:0,
@@ -188,12 +190,16 @@ export class WebglRenderer extends Disposable implements IRenderer {
188190
for(constlofthis._renderLayers){
189191
l.onBlur(this._terminal);
190192
}
193+
// Request a redraw for active/inactive selection background
194+
this._requestRedrawViewport();
191195
}
192196

193197
publiconFocus():void{
194198
for(constlofthis._renderLayers){
195199
l.onFocus(this._terminal);
196200
}
201+
// Request a redraw for active/inactive selection background
202+
this._requestRedrawViewport();
197203
}
198204

199205
publiconSelectionChanged(start:[number,number]|undefined,end:[number,number]|undefined,columnSelectMode:boolean):void{
@@ -406,7 +412,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
406412

407413
// Apply the selection color if needed
408414
if(this._isCellSelected(x,y)){
409-
bgOverride=this._colors.selectionBackgroundOpaque.rgba>>8&0xFFFFFF;
415+
bgOverride=(this._coreBrowserService.isFocused ?this._colors.selectionBackgroundOpaque :this._colors.selectionInactiveBackgroundOpaque).rgba>>8&0xFFFFFF;
410416
if(this._colors.selectionForeground){
411417
fgOverride=this._colors.selectionForeground.rgba>>8&0xFFFFFF;
412418
}

‎addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export function generateConfig(scaledCellWidth: number, scaledCellHeight: number
2121
background:colors.background,
2222
cursor:NULL_COLOR,
2323
cursorAccent:NULL_COLOR,
24+
selectionForeground:NULL_COLOR,
2425
selectionBackgroundTransparent:NULL_COLOR,
2526
selectionBackgroundOpaque:NULL_COLOR,
26-
selectionForeground:NULL_COLOR,
27+
selectionInactiveBackgroundTransparent:NULL_COLOR,
28+
selectionInactiveBackgroundOpaque:NULL_COLOR,
2729
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
2830
// dynamic character atlas.
2931
ansi:colors.ansi.slice(),

‎addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { CellData } from 'common/buffer/CellData';
1010
import{IColorSet,ITerminal}from'browser/Types';
1111
import{IRenderDimensions,IRequestRedrawEvent}from'browser/renderer/Types';
1212
import{IEventEmitter}from'common/EventEmitter';
13+
import{ICoreBrowserService}from'browser/services/Services';
14+
import{ICoreService}from'common/services/Services';
1315

1416
interfaceICursorState{
1517
x:number;
@@ -35,8 +37,9 @@ export class CursorRenderLayer extends BaseRenderLayer {
3537
container:HTMLElement,
3638
zIndex:number,
3739
colors:IColorSet,
38-
privatereadonly_terminal:ITerminal,
39-
private_onRequestRefreshRowsEvent:IEventEmitter<IRequestRedrawEvent>
40+
private_onRequestRefreshRowsEvent:IEventEmitter<IRequestRedrawEvent>,
41+
privatereadonly_coreBrowserService:ICoreBrowserService,
42+
privatereadonly_coreService:ICoreService
4043
){
4144
super(container,'cursor',zIndex,true,colors);
4245
this._state={
@@ -91,9 +94,9 @@ export class CursorRenderLayer extends BaseRenderLayer {
9194
publiconOptionsChanged(terminal:Terminal):void{
9295
if(terminal.options.cursorBlink){
9396
if(!this._cursorBlinkStateManager){
94-
this._cursorBlinkStateManager=newCursorBlinkStateManager(terminal,()=>{
97+
this._cursorBlinkStateManager=newCursorBlinkStateManager(()=>{
9598
this._render(terminal,true);
96-
});
99+
},this._coreBrowserService);
97100
}
98101
}else{
99102
this._cursorBlinkStateManager?.dispose();
@@ -118,8 +121,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
118121

119122
private_render(terminal:Terminal,triggeredByAnimationFrame:boolean):void{
120123
// Don't draw the cursor if it's hidden
121-
// TODO: Need to expose API for this
122-
if(!this._terminal.coreService.isCursorInitialized||this._terminal.coreService.isCursorHidden){
124+
if(!this._coreService.isCursorInitialized||this._coreService.isCursorHidden){
123125
this._clearCursor();
124126
return;
125127
}
@@ -142,7 +144,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
142144
return;
143145
}
144146

145-
if(!isTerminalFocused(terminal)){
147+
if(!this._coreBrowserService.isFocused){
146148
this._clearCursor();
147149
this._ctx.save();
148150
this._ctx.fillStyle=this._colors.cursor.css;
@@ -171,7 +173,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
171173
// The cursor is already in the correct spot, don't redraw
172174
if(this._state.x===cursorX&&
173175
this._state.y===viewportRelativeCursorY&&
174-
this._state.isFocused===isTerminalFocused(terminal)&&
176+
this._state.isFocused===this._coreBrowserService.isFocused&&
175177
this._state.style===terminal.options.cursorStyle&&
176178
this._state.width===this._cell.getWidth()){
177179
return;
@@ -254,11 +256,11 @@ class CursorBlinkStateManager {
254256
private_animationTimeRestarted:number|undefined;
255257

256258
constructor(
257-
terminal:Terminal,
258-
private_renderCallback:()=>void
259+
private_renderCallback:()=>void,
260+
coreBrowserService:ICoreBrowserService
259261
){
260262
this.isCursorVisible=true;
261-
if(isTerminalFocused(terminal)){
263+
if(coreBrowserService.isFocused){
262264
this._restartInterval();
263265
}
264266
}
@@ -373,7 +375,3 @@ class CursorBlinkStateManager {
373375
this.restartBlinkAnimation(terminal);
374376
}
375377
}
376-
377-
functionisTerminalFocused(terminal:Terminal):boolean{
378-
returndocument.activeElement===terminal.textarea&&document.hasFocus();
379-
}

‎src/browser/ColorManager.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ export class ColorManager implements IColorManager {
102102
background:DEFAULT_BACKGROUND,
103103
cursor:DEFAULT_CURSOR,
104104
cursorAccent:DEFAULT_CURSOR_ACCENT,
105+
selectionForeground:undefined,
105106
selectionBackgroundTransparent:DEFAULT_SELECTION,
106107
selectionBackgroundOpaque:color.blend(DEFAULT_BACKGROUND,DEFAULT_SELECTION),
107-
selectionForeground:undefined,
108+
selectionInactiveBackgroundTransparent:DEFAULT_SELECTION,
109+
selectionInactiveBackgroundOpaque:color.blend(DEFAULT_BACKGROUND,DEFAULT_SELECTION),
108110
ansi:DEFAULT_ANSI_COLORS.slice(),
109111
contrastCache:this._contrastCache
110112
};
@@ -134,6 +136,8 @@ export class ColorManager implements IColorManager {
134136
this.colors.cursorAccent=this._parseColor(theme.cursorAccent,DEFAULT_CURSOR_ACCENT,true);
135137
this.colors.selectionBackgroundTransparent=this._parseColor(theme.selectionBackground,DEFAULT_SELECTION,true);
136138
this.colors.selectionBackgroundOpaque=color.blend(this.colors.background,this.colors.selectionBackgroundTransparent);
139+
this.colors.selectionInactiveBackgroundTransparent=this._parseColor(theme.selectionInactiveBackground,this.colors.selectionBackgroundTransparent,true);
140+
this.colors.selectionInactiveBackgroundOpaque=color.blend(this.colors.background,this.colors.selectionInactiveBackgroundTransparent);
137141
constnullColor:IColor={
138142
css:'',
139143
rgba:0
@@ -151,6 +155,10 @@ export class ColorManager implements IColorManager {
151155
constopacity=0.3;
152156
this.colors.selectionBackgroundTransparent=color.opacity(this.colors.selectionBackgroundTransparent,opacity);
153157
}
158+
if(color.isOpaque(this.colors.selectionInactiveBackgroundTransparent)){
159+
constopacity=0.3;
160+
this.colors.selectionInactiveBackgroundTransparent=color.opacity(this.colors.selectionInactiveBackgroundTransparent,opacity);
161+
}
154162
this.colors.ansi=DEFAULT_ANSI_COLORS.slice();
155163
this.colors.ansi[0]=this._parseColor(theme.black,DEFAULT_ANSI_COLORS[0]);
156164
this.colors.ansi[1]=this._parseColor(theme.red,DEFAULT_ANSI_COLORS[1]);

‎src/browser/TestUtils.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import{IDisposable,IMarker,ILinkProvider,IDecorationOptions,IDecoration}from'xterm';
77
import{IEvent,EventEmitter}from'common/EventEmitter';
8-
import{ICharacterJoinerService,ICharSizeService,IMouseService,IRenderService,ISelectionService}from'browser/services/Services';
8+
import{ICharacterJoinerService,ICharSizeService,ICoreBrowserService,IMouseService,IRenderService,ISelectionService}from'browser/services/Services';
99
import{IRenderDimensions,IRenderer,IRequestRedrawEvent}from'browser/renderer/Types';
1010
import{IColorSet,ITerminal,ILinkifier2,IBrowser,IViewport,IColorManager,ICompositionHelper,CharacterJoinerHandler,IRenderDebouncer,IBufferRange}from'browser/Types';
1111
import{IBuffer,IBufferStringIterator,IBufferSet}from'common/buffer/Types';
@@ -340,6 +340,11 @@ export class MockCompositionHelper implements ICompositionHelper {
340340
}
341341
}
342342

343+
exportclassMockCoreBrowserServiceimplementsICoreBrowserService{
344+
publicserviceBrand:undefined;
345+
publicisFocused:boolean=true;
346+
}
347+
343348
exportclassMockCharSizeServiceimplementsICharSizeService{
344349
publicserviceBrand:undefined;
345350
publicgethasValidSize():boolean{returnthis.width>0&&this.height>0;}

‎src/browser/Types.d.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ export interface IColorSet {
115115
background:IColor;
116116
cursor:IColor;
117117
cursorAccent:IColor;
118+
selectionForeground:IColor|undefined;
118119
selectionBackgroundTransparent:IColor;
119120
/** The selection blended on top of background. */
120121
selectionBackgroundOpaque:IColor;
121-
selectionForeground:IColor|undefined;
122+
selectionInactiveBackgroundTransparent:IColor;
123+
selectionInactiveBackgroundOpaque:IColor;
122124
ansi:IColor[];
123125
contrastCache:IColorContrastCache;
124126
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp