From 2f356f85d3fa84e354f505f8887cba953e51cc3c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 20 Apr 2017 15:08:17 +0200 Subject: [PATCH] Make process.platform easier to mock --- spec/text-editor-component-spec.js | 11 ++++------- src/text-editor-component.js | 14 +++++--------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 832456b27..3f9282819 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -1807,10 +1807,7 @@ describe('TextEditorComponent', () => { }) it('adds or removes cursors when holding cmd or ctrl when single-clicking', () => { - const {component, editor} = buildComponent() - spyOn(component, 'getPlatform').andCallFake(() => mockedPlatform) - - let mockedPlatform = 'darwin' + const {component, editor} = buildComponent({platform: 'darwin'}) expect(editor.getCursorScreenPositions()).toEqual([[0, 0]]) // add cursor at 1, 16 @@ -1870,9 +1867,8 @@ describe('TextEditorComponent', () => { ) expect(editor.getCursorScreenPositions()).toEqual([[1, 4]]) - mockedPlatform = 'win32' - // ctrl-click adds cursors on platforms *other* than macOS + component.props.platform = 'win32' component.didMouseDownOnContent( Object.assign(clientPositionForCharacter(component, 1, 16), { detail: 1, @@ -2823,7 +2819,8 @@ function buildComponent (params = {}) { const component = new TextEditorComponent({ model: editor, rowsPerTile: params.rowsPerTile, - updatedSynchronously: false + updatedSynchronously: false, + platform: params.platform }) const {element} = component if (!editor.getAutoHeight()) { diff --git a/src/text-editor-component.js b/src/text-editor-component.js index cb7c22311..dd622939c 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -823,10 +823,6 @@ class TextEditorComponent { ) } - getPlatform () { - return process.platform - } - queryScreenLinesToRender () { const {model} = this.props @@ -1474,12 +1470,12 @@ class TextEditorComponent { } didMouseDownOnContent (event) { - const {model} = this.props + const {model, platform} = this.props const {target, button, detail, ctrlKey, shiftKey, metaKey} = event // Only handle mousedown events for left mouse button (or the middle mouse // button on Linux where it pastes the selection clipboard). - if (!(button === 0 || (this.getPlatform() === 'linux' && button === 1))) return + if (!(button === 0 || (platform === 'linux' && button === 1))) return const screenPosition = this.screenPositionForMouseEvent(event) @@ -1489,7 +1485,7 @@ class TextEditorComponent { return } - const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin') + const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin') switch (detail) { case 1: @@ -1534,7 +1530,7 @@ class TextEditorComponent { } didMouseDownOnLineNumberGutter (event) { - const {model} = this.props + const {model, platform} = this.props const {target, button, ctrlKey, shiftKey, metaKey} = event // Only handle mousedown events for left mouse button @@ -1548,7 +1544,7 @@ class TextEditorComponent { return } - const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin') + const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin') const endBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, Infinity]).row const clickedLineBufferRange = Range(Point(startBufferRow, 0), Point(endBufferRow + 1, 0))