Add altClickForMouseEvents option for issue #5952

When enabled during mouse events mode, click/drag/move events require the alt
key while wheel events are unaffected. Selection stays enabled by default
and takes precedence over macOptionClickForcesSelection.

Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-05-27 20:13:31 +00:00
co-authored by Daniel Imms
parent 95d9224b8c
commit fbb2a9710f
8 changed files with 75 additions and 9 deletions
+23 -4
View File
@@ -7,7 +7,7 @@ import { assert } from 'chai';
import { SelectionService, SelectionMode } from './SelectionService';
import { SelectionModel } from 'browser/selection/SelectionModel';
import { IBufferLine } from 'common/Types';
import { MockBufferService, MockOptionsService, MockCoreService, createCellData } from 'common/TestUtils.test';
import { MockBufferService, MockOptionsService, MockCoreService, MockMouseStateService, createCellData } from 'common/TestUtils.test';
import { BufferLine } from 'common/buffer/BufferLine';
import { BufferLineStringCache } from 'common/buffer/BufferLineStringCache';
import { IBufferService, IOptionsService } from 'common/services/Services';
@@ -22,9 +22,10 @@ class TestSelectionService extends SelectionService {
constructor(
bufferService: IBufferService,
optionsService: IOptionsService,
renderService: IRenderService
renderService: IRenderService,
public readonly mouseStateService: MockMouseStateService
) {
super(null!, null!, null!, bufferService, new MockCoreService(), new MockMouseService(), optionsService, renderService, new MockCoreBrowserService());
super(null!, null!, null!, bufferService, new MockCoreService(), new MockMouseService(), optionsService, mouseStateService, renderService, new MockCoreBrowserService());
}
public get model(): SelectionModel { return this._model; }
@@ -45,16 +46,18 @@ describe('SelectionService', () => {
let buffer: IBuffer;
let bufferService: IBufferService;
let optionsService: IOptionsService;
let mouseStateService: MockMouseStateService;
let selectionService: TestSelectionService;
beforeEach(() => {
optionsService = new MockOptionsService();
mouseStateService = new MockMouseStateService();
bufferService = new MockBufferService(20, 20, optionsService);
buffer = bufferService.buffer;
const renderService = new MockRenderService();
renderService.dimensions.css.canvas.height = 10 * 20;
renderService.dimensions.css.canvas.width = 10 * 20;
selectionService = new TestSelectionService(bufferService, optionsService, renderService);
selectionService = new TestSelectionService(bufferService, optionsService, renderService, mouseStateService);
});
function stringToRow(text: string): IBufferLine {
@@ -499,5 +502,21 @@ describe('SelectionService', () => {
assert.isFalse(selectionService.areCoordsInSelection([2, 1], [2, 0], [2, 1]));
});
});
describe('shouldForceSelection', () => {
it('should force selection without alt when altClickForMouseEvents is enabled', () => {
optionsService.options.altClickForMouseEvents = true;
mouseStateService.areMouseEventsActive = true;
assert.isTrue(selectionService.shouldForceSelection({ altKey: false } as MouseEvent));
assert.isFalse(selectionService.shouldForceSelection({ altKey: true } as MouseEvent));
});
it('should take precedence over macOptionClickForcesSelection', () => {
optionsService.options.altClickForMouseEvents = true;
optionsService.options.macOptionClickForcesSelection = true;
mouseStateService.areMouseEventsActive = true;
assert.isFalse(selectionService.shouldForceSelection({ altKey: true } as MouseEvent));
});
});
});