Skip to content

Commit e9e8206

Browse files
authored
Merge pull request #5423 from Tyriar/tyriar/resize5300
Clear selection on vertical resize
2 parents 1bf90d9 + 9a7517d commit e9e8206

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/browser/services/SelectionService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ export class SelectionService extends Disposable implements ISelectionService {
152152
this._register(toDisposable(() => {
153153
this._removeMouseDownListeners();
154154
}));
155+
156+
// Clear selection when resizing vertically. This experience could be improved, this is the
157+
// simple option to fix the buggy behavior. https://github.com/xtermjs/xterm.js/issues/5300
158+
this._register(this._bufferService.onResize(e => {
159+
if (e.rowsChanged) {
160+
this.clearSelection();
161+
}
162+
}));
155163
}
156164

157165
public reset(): void {

src/common/TestUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, ICoreMouseService, ICharsetService, UnicodeCharProperties, UnicodeCharWidth, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService } from 'common/services/Services';
6+
import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, ICoreMouseService, ICharsetService, UnicodeCharProperties, UnicodeCharWidth, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService, type IBufferResizeEvent } from 'common/services/Services';
77
import { UnicodeService } from 'common/services/UnicodeService';
88
import { clone } from 'common/Clone';
99
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
@@ -18,7 +18,7 @@ export class MockBufferService implements IBufferService {
1818
public serviceBrand: any;
1919
public get buffer(): IBuffer { return this.buffers.active; }
2020
public buffers: IBufferSet = {} as any;
21-
public onResize: Event<{ cols: number, rows: number }> = new Emitter<{ cols: number, rows: number }>().event;
21+
public onResize: Event<IBufferResizeEvent> = new Emitter<IBufferResizeEvent>().event;
2222
public onScroll: Event<number> = new Emitter<number>().event;
2323
private readonly _onScroll = new Emitter<number>();
2424
public isUserScrolling: boolean = false;

src/common/services/BufferService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
77
import { IAttributeData, IBufferLine } from 'common/Types';
88
import { BufferSet } from 'common/buffer/BufferSet';
99
import { IBuffer, IBufferSet } from 'common/buffer/Types';
10-
import { IBufferService, IOptionsService } from 'common/services/Services';
10+
import { IBufferService, IOptionsService, type IBufferResizeEvent } from 'common/services/Services';
1111
import { Emitter } from 'vs/base/common/event';
1212

1313
export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
@@ -22,7 +22,7 @@ export class BufferService extends Disposable implements IBufferService {
2222
/** Whether the user is scrolling (locks the scroll position) */
2323
public isUserScrolling: boolean = false;
2424

25-
private readonly _onResize = this._register(new Emitter<{ cols: number, rows: number }>());
25+
private readonly _onResize = this._register(new Emitter<IBufferResizeEvent>());
2626
public readonly onResize = this._onResize.event;
2727
private readonly _onScroll = this._register(new Emitter<number>());
2828
public readonly onScroll = this._onScroll.event;
@@ -43,12 +43,12 @@ export class BufferService extends Disposable implements IBufferService {
4343
}
4444

4545
public resize(cols: number, rows: number): void {
46+
const colsChanged = this.cols !== cols;
47+
const rowsChanged = this.rows !== rows;
4648
this.cols = cols;
4749
this.rows = rows;
4850
this.buffers.resize(cols, rows);
49-
// TODO: This doesn't fire when scrollback changes - add a resize event to BufferSet and forward
50-
// event
51-
this._onResize.fire({ cols, rows });
51+
this._onResize.fire({ cols, rows, colsChanged, rowsChanged });
5252
}
5353

5454
public reset(): void {

src/common/services/Services.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ export interface IBufferService {
1818
readonly buffer: IBuffer;
1919
readonly buffers: IBufferSet;
2020
isUserScrolling: boolean;
21-
onResize: Event<{ cols: number, rows: number }>;
21+
onResize: Event<IBufferResizeEvent>;
2222
onScroll: Event<number>;
2323
scroll(eraseAttr: IAttributeData, isWrapped?: boolean): void;
2424
scrollLines(disp: number, suppressScrollEvent?: boolean): void;
2525
resize(cols: number, rows: number): void;
2626
reset(): void;
2727
}
2828

29+
export interface IBufferResizeEvent {
30+
cols: number;
31+
rows: number;
32+
colsChanged: boolean;
33+
rowsChanged: boolean;
34+
}
35+
2936
export const ICoreMouseService = createDecorator<ICoreMouseService>('CoreMouseService');
3037
export interface ICoreMouseService {
3138
serviceBrand: undefined;

0 commit comments

Comments
 (0)