Skip to content

Commit

Permalink
Show parent commit ids and try to select them on click (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau authored Aug 21, 2024
1 parent b2c1a04 commit a54462e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
7 changes: 5 additions & 2 deletions components/commit/commit.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
data-bind="text: numberOfRemovedLines"
></span>
|
<span data-bind="text: sha1.substr(0, 8)"></span>
<!-- ko if: navigator.clipboard && (selected() || nodeIsMousehover()) -->
<span title="Commit" data-bind="text: sha1.substring(0, 8)"></span>
<!-- ko if: navigator.clipboard -->
<button class="btn btn-default btn-xs" type="button" data-bind="click: copyHash"><span class="glyphicon glyphicon-copy"></span></button>
<!-- /ko -->
<!-- ko foreach: parents -->
| <a href="#" title="Parent Commit" data-bind="text: $data.substring(0, 8), click: $parent.gotoCommit.bind($parent, $data)"></a>
<!-- /ko -->
</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions components/commit/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ components.register('commit', (args) => new CommitViewModel(args));

class CommitViewModel {
constructor(gitNode) {
this.graph = gitNode.graph;
this.repoPath = gitNode.graph.repoPath;
this.sha1 = gitNode.sha1;
this.server = gitNode.graph.server;
Expand All @@ -27,6 +28,7 @@ class CommitViewModel {
this.fileLineDiffs = ko.observable();
this.numberOfAddedLines = ko.observable();
this.numberOfRemovedLines = ko.observable();
this.parents = ko.observable();
this.authorGravatar = ko.computed(() => md5((this.authorEmail() || '').trim().toLowerCase()));

this.showCommitDiff = ko.computed(
Expand Down Expand Up @@ -56,6 +58,7 @@ class CommitViewModel {
this.authorEmail(args.authorEmail);
this.numberOfAddedLines(args.additions);
this.numberOfRemovedLines(args.deletions);
this.parents(args.parents || []);
this.fileLineDiffs(args.fileLineDiffs);
this.commitDiff = ko.observable(
components.create('commitDiff', {
Expand Down Expand Up @@ -88,4 +91,11 @@ class CommitViewModel {
copyHash() {
navigator.clipboard.writeText(this.sha1);
}

gotoCommit(sha1) {
const node = this.graph.nodesById[sha1];
if (node) {
node.toggleSelected();
}
}
}
39 changes: 7 additions & 32 deletions components/graph/git-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,41 +251,16 @@ class GitNodeViewModel extends Animateable {
}

toggleSelected() {
const beforeThisCR = this.commitComponent.element().getBoundingClientRect();
let beforeBelowCR = null;
if (this.belowNode) {
beforeBelowCR = this.belowNode.commitComponent.element().getBoundingClientRect();
}

let prevSelected = this.graph.currentActionContext();
if (!(prevSelected instanceof GitNodeViewModel)) prevSelected = null;
const prevSelectedCR = prevSelected
? prevSelected.commitComponent.element().getBoundingClientRect()
: null;
this.selected(!this.selected());

// If we are deselecting
if (!this.selected()) {
if (beforeThisCR.top < 0 && beforeBelowCR) {
const afterBelowCR = this.belowNode.commitComponent.element().getBoundingClientRect();
// If the next node is showing, try to keep it in the screen (no jumping)
if (beforeBelowCR.top < window.innerHeight) {
window.scrollBy(0, afterBelowCR.top - beforeBelowCR.top);
// Otherwise just try to bring them to the middle of the screen
} else {
window.scrollBy(0, afterBelowCR.top - window.innerHeight / 2);
}
}
// If we are selecting
} else {
const afterThisCR = this.commitComponent.element().getBoundingClientRect();
if (this.selected()) {
const commitElement = this.commitComponent.element();
const commitRect = commitElement.getBoundingClientRect();
if (
prevSelectedCR &&
(prevSelectedCR.top < 0 || prevSelectedCR.top > window.innerHeight) &&
afterThisCR.top != beforeThisCR.top
commitRect.top <
+window.getComputedStyle(document.documentElement).scrollPaddingTop.replace('px', '') ||
commitRect.bottom > document.documentElement.clientHeight
) {
window.scrollBy(0, -(beforeThisCR.top - afterThisCR.top));
console.log('Fix');
commitElement.scrollIntoView();
}
}
return false;
Expand Down
5 changes: 5 additions & 0 deletions components/header/header.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@import 'public/less/variables.less';

html {
scroll-behavior: smooth;
scroll-padding-top: 100px;
}

.navbarPadder {
height: 81px;
}
Expand Down
4 changes: 2 additions & 2 deletions source/git-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ exports.parseGitSubmodule = (text) => {
if (url.indexOf('http') != 0) {
if (url.indexOf('git:') == 0) {
// git
url = `http${url.substr(url.indexOf(':'))}`;
url = `http${url.substring(url.indexOf(':'))}`;
} else {
// ssh
url = `http://${url.substr(url.indexOf('@') + 1).replace(':', '/')}`;
url = `http://${url.substring(url.indexOf('@') + 1).replace(':', '/')}`;
}
}

Expand Down

0 comments on commit a54462e

Please sign in to comment.