feat: add setting to disable multi cursor on click

This commit is contained in:
Tony Brix 2020-02-24 17:30:57 -06:00
parent 917a00e195
commit d5c3c9661d
3 changed files with 114 additions and 1 deletions

View File

@ -4183,6 +4183,7 @@ describe('TextEditorComponent', () => {
});
it('adds or removes cursors when holding cmd or ctrl when single-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', true);
const { component, editor } = buildComponent({ platform: 'darwin' });
expect(editor.getCursorScreenPositions()).toEqual([[0, 0]]);
@ -4263,6 +4264,7 @@ describe('TextEditorComponent', () => {
});
it('adds word selections when holding cmd or ctrl when double-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', true);
const { component, editor } = buildComponent();
editor.addCursorAtScreenPosition([1, 16], { autoscroll: false });
expect(editor.getCursorScreenPositions()).toEqual([[0, 0], [1, 16]]);
@ -4289,6 +4291,7 @@ describe('TextEditorComponent', () => {
});
it('adds line selections when holding cmd or ctrl when triple-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', true);
const { component, editor } = buildComponent();
editor.addCursorAtScreenPosition([1, 16], { autoscroll: false });
expect(editor.getCursorScreenPositions()).toEqual([[0, 0], [1, 16]]);
@ -4327,6 +4330,107 @@ describe('TextEditorComponent', () => {
expect(editor.testAutoscrollRequests).toEqual([]);
});
it('does not add cursors when holding cmd or ctrl when single-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', false);
const { component, editor } = buildComponent({ platform: 'darwin' });
expect(editor.getCursorScreenPositions()).toEqual([[0, 0]]);
// moves cursor to 1, 16
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 16), {
detail: 1,
button: 0,
metaKey: true
})
);
expect(editor.getCursorScreenPositions()).toEqual([[1, 16]]);
// ctrl-click does not add cursors on macOS, nor does it move the cursor
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 4), {
detail: 1,
button: 0,
ctrlKey: true
})
);
expect(editor.getSelectedScreenRanges()).toEqual([
[[1, 16], [1, 16]]
]);
// ctrl-click does not add cursors on platforms *other* than macOS
component.props.platform = 'win32';
editor.setCursorScreenPosition([1, 4], { autoscroll: false });
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 16), {
detail: 1,
button: 0,
ctrlKey: true
})
);
expect(editor.getCursorScreenPositions()).toEqual([[1, 16]]);
expect(editor.testAutoscrollRequests).toEqual([]);
});
it('does not add word selections when holding cmd or ctrl when double-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', false);
const { component, editor } = buildComponent();
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 16), {
detail: 1,
button: 0,
metaKey: true
})
);
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 16), {
detail: 2,
button: 0,
metaKey: true
})
);
expect(editor.getSelectedScreenRanges()).toEqual([
[[1, 13], [1, 21]]
]);
expect(editor.testAutoscrollRequests).toEqual([]);
});
it('does not add line selections when holding cmd or ctrl when triple-clicking', () => {
atom.config.set('core.editor.multiCursorOnClick', false);
const { component, editor } = buildComponent();
const { clientX, clientY } = clientPositionForCharacter(
component,
1,
16
);
component.didMouseDownOnContent({
detail: 1,
button: 0,
metaKey: true,
clientX,
clientY
});
component.didMouseDownOnContent({
detail: 2,
button: 0,
metaKey: true,
clientX,
clientY
});
component.didMouseDownOnContent({
detail: 3,
button: 0,
metaKey: true,
clientX,
clientY
});
expect(editor.getSelectedScreenRanges()).toEqual([[[1, 0], [2, 0]]]);
expect(editor.testAutoscrollRequests).toEqual([]);
});
it('expands the last selection on shift-click', () => {
const { component, editor } = buildComponent();
@ -4415,6 +4519,7 @@ describe('TextEditorComponent', () => {
});
it('expands the last selection on drag', () => {
atom.config.set('core.editor.multiCursorOnClick', true);
const { component, editor } = buildComponent();
spyOn(component, 'handleMouseDragUntilMouseUp');

View File

@ -609,6 +609,12 @@ const configSchema = {
default: process.platform !== 'darwin',
description:
'Change the editor font size when pressing the Ctrl key and scrolling the mouse up/down.'
},
multiCursorOnClick: {
type: 'boolean',
default: true,
description:
'Add multiple cursors when pressing the Ctrl key (Command key on MacOS) and clicking the editor.'
}
}
}

View File

@ -1991,7 +1991,9 @@ module.exports = class TextEditorComponent {
return;
}
const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin');
const allowMultiCursor = atom.config.get('core.editor.multiCursorOnClick');
const addOrRemoveSelection =
allowMultiCursor && (metaKey || (ctrlKey && platform !== 'darwin'));
switch (detail) {
case 1: