From a54462ee2b45ec3f880949dd02219a9e3a3ff929 Mon Sep 17 00:00:00 2001 From: campersau Date: Wed, 21 Aug 2024 20:11:49 +0200 Subject: [PATCH] Show parent commit ids and try to select them on click (#1599) --- components/commit/commit.html | 7 +++++-- components/commit/commit.js | 10 +++++++++ components/graph/git-node.js | 39 +++++++---------------------------- components/header/header.less | 5 +++++ source/git-parser.js | 4 ++-- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/components/commit/commit.html b/components/commit/commit.html index 5742b391e..4dc75c99b 100644 --- a/components/commit/commit.html +++ b/components/commit/commit.html @@ -42,10 +42,13 @@ data-bind="text: numberOfRemovedLines" > | - - + + + + | + diff --git a/components/commit/commit.js b/components/commit/commit.js index 5f728e9f4..4ca72f15d 100644 --- a/components/commit/commit.js +++ b/components/commit/commit.js @@ -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; @@ -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( @@ -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', { @@ -88,4 +91,11 @@ class CommitViewModel { copyHash() { navigator.clipboard.writeText(this.sha1); } + + gotoCommit(sha1) { + const node = this.graph.nodesById[sha1]; + if (node) { + node.toggleSelected(); + } + } } diff --git a/components/graph/git-node.js b/components/graph/git-node.js index b7c00eb25..de9e1edcb 100644 --- a/components/graph/git-node.js +++ b/components/graph/git-node.js @@ -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; diff --git a/components/header/header.less b/components/header/header.less index 736173e8c..17323a959 100644 --- a/components/header/header.less +++ b/components/header/header.less @@ -1,5 +1,10 @@ @import 'public/less/variables.less'; +html { + scroll-behavior: smooth; + scroll-padding-top: 100px; +} + .navbarPadder { height: 81px; } diff --git a/source/git-parser.js b/source/git-parser.js index 822f9627b..0ac798440 100644 --- a/source/git-parser.js +++ b/source/git-parser.js @@ -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(':', '/')}`; } }