Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Open diff from editor #879

Merged
merged 14 commits into from
May 30, 2017
Merged

Open diff from editor #879

merged 14 commits into from
May 30, 2017

Conversation

kuychaco
Copy link
Contributor

@kuychaco kuychaco commented May 26, 2017

Closes #888
Closes #46

This PR adds commands for easily viewing the diff associated with the active editor:

  • github:view-unstaged-changes-for-current-file
  • github:view-staged-changes-for-current-file

The RootController class

  1. grabs the active editor
  2. determines the cursor location
  3. selects the associated item in the list view
  4. opens the staged or unstaged file diff associated with the file
  5. selects the closest added hunk line based on cursor position and scrolls it into view if necessary

As part of this the FilePatchSelection API was extended to include a goToDiffLine(lineNumber) method which selects the closest added line based on the passed in line number. This can be used for a github:go-to-diff-line command similar to Atom's go-to-line functionality in editors. This is outside of the scope of the current PR, and may be implemented separately at a later point.

@simurai
Copy link
Contributor

simurai commented May 27, 2017

Great addition. 😍

Should it open in a split pane?

Also, I wonder if this replaces the "stage from editor" #46? For very small changes, it's ok to "blindly" stage without seeing a diff. But otherwise it's nice be able to take a quick look what you're going to stage.

I think eventually, we should still offer some kind of "quick commit" option, but that's for another PR.

@kuychaco kuychaco force-pushed the ku-open-diff-from-editor branch from 5cf52fb to 6f1aba3 Compare May 29, 2017 13:30
@kuychaco kuychaco force-pushed the ku-open-diff-from-editor branch from 6f1aba3 to a1541b2 Compare May 29, 2017 14:58
@kuychaco kuychaco force-pushed the ku-open-diff-from-editor branch 2 times, most recently from d25e493 to ab16969 Compare May 30, 2017 13:57
@kuychaco kuychaco force-pushed the ku-open-diff-from-editor branch from e3007d4 to 378cf85 Compare May 30, 2017 14:21
@kuychaco
Copy link
Contributor Author

kuychaco commented May 30, 2017

Should it open in a split pane?

Good idea @simurai. Added a config option (similar to what we have for find-and-replace results) that defaults to opening in the current pane, but gives users the option of splitting right or down

diff-in-pane

Also, I wonder if this replaces the "stage from editor" #46?

Yeah, I think this is a good alternative/replacement to staging directly from the editor. You think it's cool if I close out that issue with this PR?

Copy link
Contributor

@smashwilson smashwilson left a comment

Choose a reason for hiding this comment

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

One typo and a bunch of idle thoughts about further work from me. 👍

@@ -364,7 +364,7 @@ export default class GitTabController {

@autobind
quietlySelectItem(filePath, stagingStatus) {
return this.refs.gitTab.quitelySelectItem(filePath, stagingStatus);
return this.refs.gitTab.quietlySelectItem(filePath, stagingStatus);
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops 🙈

@@ -43,7 +43,7 @@ export default class RootController extends React.Component {
static propTypes = {
workspace: PropTypes.object.isRequired,
commandRegistry: PropTypes.object.isRequired,
notificationManager: PropTypes.object.isRequired,
notificationManager: PropTypes.object.isReuired,
Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ It looks like this one was spelled right the first time? Caught a stray backspace keypress maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

amending: stagingStatus === 'staged' && this.state.isAmending,
});
} else {
throw new Error(`${absFilePath} does not belong to repo ${repoPath}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking this through: because the active text editor sets the active repository context, the only time that this could happen is if it's triggered in the window between opening an editor on a file not in the active repository and the render context change completing. Performance captures indicate that window is only in the tens of milliseconds range, so it's unlikely that anyone could hit this manually.

Eventually we might want to add logic to the effect of "wait on a Promise that resolves when the active context is what we expect it to be, then trigger diveIntoFilePatchForPath." Not worth holding up an initial merge for though I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just adding my two cents — my gut reaction is to feel slightly uncomfortable with assuming that the active repository is the one we want to use for all operations. For example, I've wanted the ability to "pin" a repo so that it's always active for a while now. On a related note, I think that the diff views should render irrespective of the active repository; that is, they set and maintain their own context outside of the "active" one.


@autobind
viewUnstagedChangesForCurrentFile() {
this.viewChangesForCurrentFile('unstaged');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd ❤️ to turn 'unstaged' and 'staged' into Symbols or another more enum-ish, non-String type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion. I'll take a look into refactoring in a separate PR :)

}
}

return this.selectLine(closestLine);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 This is pretty cool. 😄

@autobind
goToDiffLine(lineNumber) {
return this.filePatchController.goToDiffLine(lineNumber);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing actions down the component hierarchy like this really feels like a "we should start looking at introducing Redux" smell to me 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this felt icky to me. IIRC @BinaryMuse looked into Redux and dismissed using it for some reason. Can't remember what

Copy link
Contributor

Choose a reason for hiding this comment

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

The way we manage model data doesn't suit itself well to Redux in my opinion. I also wanted to live with explicit props for a while to ensure we didn't switch to something a little more magical unless we really felt the pain and needed to — the abstraction, like any other, has a cost, and already the more meta-programmy parts of the package are the hardest to understand.

I do think we could use the other half of Redux — actions on the context — to good effect in the package. For example, anything that lives on the AtomEnvironment global could be placed on the context and components that need them could be wrapped in an HoC that accesses them (but allows them to be passed explicitly as props in tests). And other methods that perform actions that do not directly modify state and that do not affect rendering could be passed on context, as long as we're careful and selective about it.

@@ -182,7 +182,7 @@ export default class GitTabView {
}

@autobind
quitelySelectItem(filePath, stagingStatus) {
quietlySelectItem(filePath, stagingStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Haha oh wow. How many times have my eyes just glossed riiight over this one 😆

{
'label': 'View Staged Changes',
'command': 'github:view-staged-changes-for-current-file'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any opinions on keybindings to roll into #790 for these events?

@kuychaco kuychaco merged commit 906a7c1 into master May 30, 2017
@kuychaco kuychaco deleted the ku-open-diff-from-editor branch May 30, 2017 16:31
@smashwilson
Copy link
Contributor

Fixes #889 instead of #888 😁

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter changed file lists Highlight changed lines in the editor and stage them
4 participants