Skip to content

Commit cef19ec

Browse files
devvaannshabose
authored andcommitted
fix: git getting refreshed everytime when live preview is clicked
1 parent 44f8e25 commit cef19ec

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • src/extensions/default/Git/src

src/extensions/default/Git/src/Main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,30 @@ define(function (require, exports) {
411411
let scheduledRefresh = null;
412412
const REFRESH_DEDUPE_TIME = 3000;
413413

414+
// this variable tracks if user clicked on the live preview iframe
415+
// this is done cause when live preview iframe is clicked in highlight/edit mode,
416+
// we set cursor back to the editor because of which editor regains focus and refreshes git
417+
let focusWentToLivePreview = false;
418+
419+
// when editor window loses focus we check if focus went to live preview,
420+
// if it did, then we just set the flag to true
421+
$(window).on("blur", function () {
422+
// delay to let activeElement update
423+
setTimeout(function () {
424+
const activeEl = document.activeElement;
425+
if (activeEl && activeEl.id === "panel-live-preview-frame") {
426+
focusWentToLivePreview = true;
427+
}
428+
}, 0);
429+
});
430+
414431
function refreshOnFocusChange() {
432+
// ignore git refresh if focus went to live preview
433+
if (focusWentToLivePreview) {
434+
focusWentToLivePreview = false;
435+
return;
436+
}
437+
415438
// to sync external git changes after switching to app.
416439
if (gitEnabled) {
417440
const isGitPanelVisible = Panel.getPanel().is(":visible");

0 commit comments

Comments
 (0)