diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index b34d3d766..ac6a0cba4 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -2731,6 +2731,8 @@ describe('TextEditorComponent', () => { clientY: clientTopForLine(component, 3) + lineHeight / 2 }) expect(editor.getCursorScreenPosition()).toEqual([3, 16]) + + expect(editor.testAutoscrollRequests).toEqual([]) }) it('selects words on double-click', () => { @@ -2739,6 +2741,7 @@ describe('TextEditorComponent', () => { component.didMouseDownOnContent({detail: 1, button: 0, clientX, clientY}) component.didMouseDownOnContent({detail: 2, button: 0, clientX, clientY}) expect(editor.getSelectedScreenRange()).toEqual([[1, 13], [1, 21]]) + expect(editor.testAutoscrollRequests).toEqual([]) }) it('selects lines on triple-click', () => { @@ -2748,6 +2751,7 @@ describe('TextEditorComponent', () => { component.didMouseDownOnContent({detail: 2, button: 0, clientX, clientY}) component.didMouseDownOnContent({detail: 3, button: 0, clientX, clientY}) expect(editor.getSelectedScreenRange()).toEqual([[1, 0], [2, 0]]) + expect(editor.testAutoscrollRequests).toEqual([]) }) it('adds or removes cursors when holding cmd or ctrl when single-clicking', () => { @@ -2785,7 +2789,7 @@ describe('TextEditorComponent', () => { expect(editor.getCursorScreenPositions()).toEqual([[1, 16]]) // cmd-clicking within a selection destroys it - editor.addSelectionForScreenRange([[2, 10], [2, 15]]) + editor.addSelectionForScreenRange([[2, 10], [2, 15]], {autoscroll: false}) expect(editor.getSelectedScreenRanges()).toEqual([ [[1, 16], [1, 16]], [[2, 10], [2, 15]] @@ -2815,7 +2819,7 @@ describe('TextEditorComponent', () => { // ctrl-click adds cursors on platforms *other* than macOS component.props.platform = 'win32' - editor.setCursorScreenPosition([1, 4]) + editor.setCursorScreenPosition([1, 4], {autoscroll: false}) component.didMouseDownOnContent( Object.assign(clientPositionForCharacter(component, 1, 16), { detail: 1, @@ -2824,11 +2828,13 @@ describe('TextEditorComponent', () => { }) ) expect(editor.getCursorScreenPositions()).toEqual([[1, 4], [1, 16]]) + + expect(editor.testAutoscrollRequests).toEqual([]) }) it('adds word selections when holding cmd or ctrl when double-clicking', () => { const {component, editor} = buildComponent() - editor.addCursorAtScreenPosition([1, 16]) + editor.addCursorAtScreenPosition([1, 16], {autoscroll: false}) expect(editor.getCursorScreenPositions()).toEqual([[0, 0], [1, 16]]) component.didMouseDownOnContent( @@ -2849,11 +2855,12 @@ describe('TextEditorComponent', () => { [[0, 0], [0, 0]], [[1, 13], [1, 21]] ]) + expect(editor.testAutoscrollRequests).toEqual([]) }) it('adds line selections when holding cmd or ctrl when triple-clicking', () => { const {component, editor} = buildComponent() - editor.addCursorAtScreenPosition([1, 16]) + editor.addCursorAtScreenPosition([1, 16], {autoscroll: false}) expect(editor.getCursorScreenPositions()).toEqual([[0, 0], [1, 16]]) const {clientX, clientY} = clientPositionForCharacter(component, 1, 16) @@ -2865,12 +2872,13 @@ describe('TextEditorComponent', () => { [[0, 0], [0, 0]], [[1, 0], [2, 0]] ]) + expect(editor.testAutoscrollRequests).toEqual([]) }) it('expands the last selection on shift-click', () => { const {component, element, editor} = buildComponent() - editor.setCursorScreenPosition([2, 18]) + editor.setCursorScreenPosition([2, 18], {autoscroll: false}) component.didMouseDownOnContent(Object.assign({ detail: 1, button: 0, @@ -2887,8 +2895,8 @@ describe('TextEditorComponent', () => { // reorients word-wise selections to keep the word selected regardless of // where the subsequent shift-click occurs - editor.setCursorScreenPosition([2, 18]) - editor.getLastSelection().selectWord() + editor.setCursorScreenPosition([2, 18], {autoscroll: false}) + editor.getLastSelection().selectWord({autoscroll: false}) component.didMouseDownOnContent(Object.assign({ detail: 1, button: 0, @@ -2905,8 +2913,8 @@ describe('TextEditorComponent', () => { // reorients line-wise selections to keep the word selected regardless of // where the subsequent shift-click occurs - editor.setCursorScreenPosition([2, 18]) - editor.getLastSelection().selectLine() + editor.setCursorScreenPosition([2, 18], {autoscroll: false}) + editor.getLastSelection().selectLine(null, {autoscroll: false}) component.didMouseDownOnContent(Object.assign({ detail: 1, button: 0, @@ -2920,6 +2928,8 @@ describe('TextEditorComponent', () => { shiftKey: true }, clientPositionForCharacter(component, 3, 11))) expect(editor.getSelectedScreenRange()).toEqual([[2, 0], [4, 0]]) + + expect(editor.testAutoscrollRequests).toEqual([]) }) it('expands the last selection on drag', () => { @@ -4275,7 +4285,10 @@ function buildEditor (params = {}) { for (const paramName of ['mini', 'autoHeight', 'autoWidth', 'lineNumberGutterVisible', 'showLineNumbers', 'placeholderText', 'softWrapped', 'scrollSensitivity']) { if (params[paramName] != null) editorParams[paramName] = params[paramName] } - return new TextEditor(editorParams) + const editor = new TextEditor(editorParams) + editor.testAutoscrollRequests = [] + editor.onDidRequestAutoscroll((request) => { editor.testAutoscrollRequests.push(request) }) + return editor } function buildComponent (params = {}) { diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 941bffc8d..c34a58dad 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1763,22 +1763,22 @@ class TextEditorComponent { if (existingSelection) { if (model.hasMultipleCursors()) existingSelection.destroy() } else { - model.addCursorAtScreenPosition(screenPosition) + model.addCursorAtScreenPosition(screenPosition, {autoscroll: false}) } } else { if (shiftKey) { - model.selectToScreenPosition(screenPosition) + model.selectToScreenPosition(screenPosition, {autoscroll: false}) } else { - model.setCursorScreenPosition(screenPosition) + model.setCursorScreenPosition(screenPosition, {autoscroll: false}) } } break case 2: - if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition) + if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition, {autoscroll: false}) model.getLastSelection().selectWord({autoscroll: false}) break case 3: - if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition) + if (addOrRemoveSelection) model.addCursorAtScreenPosition(screenPosition, {autoscroll: false}) model.getLastSelection().selectLine(null, {autoscroll: false}) break }