Skip to content

Commit f109cc4

Browse files
committed
fix: git not getting updated when git panel gets visible
1 parent ba4c2aa commit f109cc4

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/extensions/default/Git/src/Branch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ define(function (require, exports) {
623623
refresh();
624624
});
625625

626+
EventEmitter.on(Events.GIT_PANEL_SHOWN, function () {
627+
refresh();
628+
});
629+
626630
EventEmitter.on(Events.GIT_ENABLED, function () {
627631
$("#git-branch-dropdown-toggle").removeClass("forced-inVisible");
628632
});

src/extensions/default/Git/src/Events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ define(function (require, exports) {
4646
exports.HISTORY_SHOW_GLOBAL = "history_showGlobal";
4747
exports.REFRESH_COUNTERS = "refresh_counters";
4848
exports.REFRESH_HISTORY = "refresh_history";
49+
exports.GIT_PANEL_SHOWN = "git_panel_shown";
4950

5051
// Git results
5152
exports.GIT_STATUS_RESULTS = "git_status_results";

src/extensions/default/Git/src/Panel.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ define(function (require, exports) {
6161
$tableContainer = $(null),
6262
lastCommitMessage = {};
6363

64+
let lastVisibleRefreshTime = 0;
65+
6466
function lintFile(filename) {
6567
var fullPath = Preferences.get("currentGitRoot") + filename,
6668
codeInspectionPromise;
@@ -899,6 +901,9 @@ define(function (require, exports) {
899901
}
900902

901903
function refresh() {
904+
if (gitPanel && gitPanel.isVisible()) {
905+
lastVisibleRefreshTime = Date.now();
906+
}
902907
// set the history panel to false and remove the class that show the button history active when refresh
903908
$gitPanel.find(".git-history-toggle").removeClass("active").attr("title", Strings.TOOLTIP_SHOW_HISTORY);
904909
$gitPanel.find(".git-file-history").removeClass("active").attr("title", Strings.TOOLTIP_SHOW_FILE_HISTORY);
@@ -1611,6 +1616,26 @@ define(function (require, exports) {
16111616
}
16121617
});
16131618

1619+
const SHOWN_REFRESH_DEDUPE_MS = 500;
1620+
1621+
function _refreshOnPanelShown() {
1622+
if (!gitPanel || gitPanelDisabled) {
1623+
return;
1624+
}
1625+
1626+
// deferred because when the panel is shown via toggle(), the shown event
1627+
// fires from within setVisible() before toggle() calls refresh() itself.
1628+
// by the time this runs, that refresh has stamped lastVisibleRefreshTime
1629+
// and this becomes a no-op instead of a duplicate git status run.
1630+
window.setTimeout(function () {
1631+
if (!gitPanel.isVisible() || Date.now() - lastVisibleRefreshTime < SHOWN_REFRESH_DEDUPE_MS) {
1632+
return;
1633+
}
1634+
1635+
EventEmitter.emit(Events.GIT_PANEL_SHOWN);
1636+
}, 0);
1637+
}
1638+
16141639
WorkspaceManager.on(WorkspaceManager.EVENT_WORKSPACE_PANEL_SHOWN, function (event, panelID) {
16151640
if (!Main.$icon) {
16161641
return;
@@ -1619,6 +1644,9 @@ define(function (require, exports) {
16191644
Main.$icon.toggleClass("on", isGitActive);
16201645
Main.$icon.toggleClass("selected-button", isGitActive);
16211646
_setTogglePanelChecked(isGitActive);
1647+
if (isGitActive) {
1648+
_refreshOnPanelShown();
1649+
}
16221650
});
16231651

16241652
exports.init = init;

0 commit comments

Comments
 (0)