Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/containers/issueish-detail-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {QueryRenderer, graphql} from 'react-relay';

import {autobind, PAGE_SIZE} from '../helpers';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
import {GithubLoginModelPropType, ItemTypePropType, EndpointPropType} from '../prop-types';
import {GithubLoginModelPropType, ItemTypePropType, EndpointPropType, RefHolderPropType} from '../prop-types';
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
import GithubLoginView from '../views/github-login-view';
import LoadingView from '../views/loading-view';
Expand Down Expand Up @@ -42,6 +42,7 @@ export default class IssueishDetailContainer extends React.Component {

// Item context
itemType: ItemTypePropType.isRequired,
refEditor: RefHolderPropType.isRequired,
}

constructor(props) {
Expand Down Expand Up @@ -211,6 +212,7 @@ export default class IssueishDetailContainer extends React.Component {

itemType={this.props.itemType}
destroy={this.props.destroy}
refEditor={this.props.refEditor}
/>
);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/controllers/issueish-detail-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import {graphql, createFragmentContainer} from 'react-relay';
import PropTypes from 'prop-types';

import {BranchSetPropType, RemoteSetPropType, ItemTypePropType, EndpointPropType} from '../prop-types';
import {
BranchSetPropType, RemoteSetPropType, ItemTypePropType, EndpointPropType, RefHolderPropType,
} from '../prop-types';
import {GitError} from '../git-shell-out-strategy';
import EnableableOperation from '../models/enableable-operation';
import PullRequestDetailView, {checkoutStates} from '../views/pr-detail-view';
Expand Down Expand Up @@ -56,6 +58,7 @@ export class BareIssueishDetailController extends React.Component {

// Item context
itemType: ItemTypePropType.isRequired,
refEditor: RefHolderPropType.isRequired,
}

constructor(props) {
Expand Down Expand Up @@ -144,6 +147,7 @@ export class BareIssueishDetailController extends React.Component {

itemType={this.props.itemType}
destroy={this.props.destroy}
refEditor={this.props.refEditor}
/>
);
} else {
Expand Down
12 changes: 12 additions & 0 deletions lib/items/changed-file-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Emitter} from 'event-kit';
import {WorkdirContextPoolPropType} from '../prop-types';
import {autobind} from '../helpers';
import ChangedFileContainer from '../containers/changed-file-container';
import RefHolder from '../models/ref-holder';

export default class ChangedFileItem extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -41,6 +42,11 @@ export default class ChangedFileItem extends React.Component {
this.emitter = new Emitter();
this.isDestroyed = false;
this.hasTerminatedPendingState = false;

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

getTitle() {
Expand Down Expand Up @@ -81,11 +87,17 @@ export default class ChangedFileItem extends React.Component {
itemType={this.constructor}
repository={repository}
destroy={this.destroy}
refEditor={this.refEditor}
{...this.props}
/>
);
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

serialize() {
return {
deserializer: 'FilePatchControllerStub',
Expand Down
11 changes: 11 additions & 0 deletions lib/items/commit-detail-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default class CommitDetailItem extends React.Component {
this.hasTerminatedPendingState = false;
this.shouldFocus = true;
this.refInitialFocus = new RefHolder();

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

terminatePendingState() {
Expand Down Expand Up @@ -61,6 +66,7 @@ export default class CommitDetailItem extends React.Component {
repository={repository}
{...this.props}
destroy={this.destroy}
refEditor={this.refEditor}
refInitialFocus={this.refInitialFocus}
/>
);
Expand All @@ -74,6 +80,11 @@ export default class CommitDetailItem extends React.Component {
return 'git-commit';
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

getWorkingDirectory() {
return this.props.workingDirectory;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/items/commit-preview-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export default class CommitPreviewItem extends React.Component {
this.isDestroyed = false;
this.hasTerminatedPendingState = false;
this.refInitialFocus = new RefHolder();

this.refEditor = new RefHolder();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean about cleaning up our items so they aren't so repetitive.

this.refEditor.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

terminatePendingState() {
Expand Down Expand Up @@ -63,6 +68,7 @@ export default class CommitPreviewItem extends React.Component {
repository={repository}
{...this.props}
destroy={this.destroy}
refEditor={this.refEditor}
refInitialFocus={this.refInitialFocus}
/>
);
Expand All @@ -76,6 +82,11 @@ export default class CommitPreviewItem extends React.Component {
return 'tasklist';
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

getWorkingDirectory() {
return this.props.workingDirectory;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/items/issueish-detail-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {addEvent} from '../reporter-proxy';
import Repository from '../models/repository';
import {getEndpoint} from '../models/endpoint';
import IssueishDetailContainer from '../containers/issueish-detail-container';
import RefHolder from '../models/ref-holder';

export default class IssueishDetailItem extends Component {
static propTypes = {
Expand Down Expand Up @@ -66,6 +67,11 @@ export default class IssueishDetailItem extends Component {
if (repository.isAbsent()) {
this.switchToIssueish(this.props.owner, this.props.repo, this.props.issueishNumber);
}

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

render() {
Expand All @@ -89,6 +95,7 @@ export default class IssueishDetailItem extends Component {

destroy={this.destroy}
itemType={this.constructor}
refEditor={this.refEditor}
/>
);
}
Expand Down Expand Up @@ -176,4 +183,9 @@ export default class IssueishDetailItem extends Component {
getTitle() {
return this.title;
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}
}
4 changes: 4 additions & 0 deletions lib/views/multi-file-patch-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class MultiFilePatchView extends React.Component {
toggleSymlinkChange: PropTypes.func,
undoLastDiscard: PropTypes.func,
discardRows: PropTypes.func,
refEditor: RefHolderPropType,
refInitialFocus: RefHolderPropType,
itemType: ItemTypePropType.isRequired,
}
Expand Down Expand Up @@ -88,6 +89,9 @@ export default class MultiFilePatchView extends React.Component {
this.subs.add(
this.refEditor.observe(editor => {
this.refEditorElement.setter(editor.getElement());
if (this.props.refEditor) {
this.props.refEditor.setter(editor);
}
}),
this.refEditorElement.observe(element => {
this.props.refInitialFocus && this.props.refInitialFocus.setter(element);
Expand Down
4 changes: 3 additions & 1 deletion lib/views/pr-detail-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import cx from 'classnames';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';

import {EnableableOperationPropType, ItemTypePropType, EndpointPropType} from '../prop-types';
import {EnableableOperationPropType, ItemTypePropType, EndpointPropType, RefHolderPropType} from '../prop-types';
import {addEvent} from '../reporter-proxy';
import PeriodicRefresher from '../periodic-refresher';
import Octicon from '../atom/octicon';
Expand Down Expand Up @@ -99,6 +99,7 @@ export class BarePullRequestDetailView extends React.Component {

// Item context
itemType: ItemTypePropType.isRequired,
refEditor: RefHolderPropType.isRequired,
}

state = {
Expand Down Expand Up @@ -207,6 +208,7 @@ export class BarePullRequestDetailView extends React.Component {
config={this.props.config}

itemType={this.props.itemType}
refEditor={this.props.refEditor}
destroy={this.props.destroy}

shouldRefetch={this.state.refreshing}
Expand Down
34 changes: 34 additions & 0 deletions test/items/changed-file-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,38 @@ describe('ChangedFileItem', function() {
assert.strictEqual(item.getWorkingDirectory(), '/dir');
assert.isTrue(item.isFilePatchItem());
});

describe('observeEmbeddedTextEditor() to interoperate with find-and-replace', function() {
let sub, editor;

beforeEach(function() {
editor = Symbol('editor');
});

afterEach(function() {
sub && sub.dispose();
});

it('calls its callback immediately if an editor is present', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

wrapper.update().find('ChangedFileContainer').prop('refEditor').setter(editor);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);
assert.isTrue(cb.calledWith(editor));
});

it('calls its callback later if the editor changes', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);

wrapper.update().find('ChangedFileContainer').prop('refEditor').setter(editor);
assert.isTrue(cb.calledWith(editor));
});
});
});
34 changes: 34 additions & 0 deletions test/items/commit-detail-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,38 @@ describe('CommitDetailItem', function() {
assert.isFalse(focusSpy.called);
});
});

describe('observeEmbeddedTextEditor() to interoperate with find-and-replace', function() {
let sub, editor;

beforeEach(function() {
editor = Symbol('editor');
});

afterEach(function() {
sub && sub.dispose();
});

it('calls its callback immediately if an editor is present', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

wrapper.update().find('CommitDetailContainer').prop('refEditor').setter(editor);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);
assert.isTrue(cb.calledWith(editor));
});

it('calls its callback later if the editor changes', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);

wrapper.update().find('CommitDetailContainer').prop('refEditor').setter(editor);
assert.isTrue(cb.calledWith(editor));
});
});
});
34 changes: 34 additions & 0 deletions test/items/commit-preview-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,38 @@ describe('CommitPreviewItem', function() {
item.focus();
});
});

describe('observeEmbeddedTextEditor() to interoperate with find-and-replace', function() {
let sub, editor;

beforeEach(function() {
editor = Symbol('editor');
});

afterEach(function() {
sub && sub.dispose();
});

it('calls its callback immediately if an editor is present', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

wrapper.update().find('CommitPreviewContainer').prop('refEditor').setter(editor);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);
assert.isTrue(cb.calledWith(editor));
});

it('calls its callback later if the editor changes', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);

wrapper.update().find('CommitPreviewContainer').prop('refEditor').setter(editor);
assert.isTrue(cb.calledWith(editor));
});
});
});
35 changes: 35 additions & 0 deletions test/items/issueish-detail-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,39 @@ describe('IssueishDetailItem', function() {
item.terminatePendingState();
assert.strictEqual(handler.callCount, 1);
});

describe('observeEmbeddedTextEditor() to interoperate with find-and-replace', function() {
let sub, uri, editor;

beforeEach(function() {
editor = Symbol('editor');
uri = IssueishDetailItem.buildURI('one.com', 'me', 'code', 400, __dirname);
});

afterEach(function() {
sub && sub.dispose();
});

it('calls its callback immediately if an editor is present', async function() {
const wrapper = mount(buildApp());
const item = await atomEnv.workspace.open(uri);

wrapper.update().find('IssueishDetailContainer').prop('refEditor').setter(editor);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);
assert.isTrue(cb.calledWith(editor));
});

it('calls its callback later if the editor changes', async function() {
const wrapper = mount(buildApp());
const item = await atomEnv.workspace.open(uri);

const cb = sinon.spy();
sub = item.observeEmbeddedTextEditor(cb);

wrapper.update().find('IssueishDetailContainer').prop('refEditor').setter(editor);
assert.isTrue(cb.calledWith(editor));
});
});
});