Skip to content

Commit e9df8b2

Browse files
committed
fix: prevent image gallery and AI box to disappear when live preview is scrolled
1 parent 54e7925 commit e9df8b2

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,7 +3862,9 @@ function RemoteFunctions(config = {}) {
38623862

38633863
// 4 is just for pixelated differences
38643864
if (Math.abs(calcNewDifference - prevDifference) > 4) {
3865-
dismissUIAndCleanupState();
3865+
dismissNodeInfoBox();
3866+
dismissNodeMoreOptionsBox();
3867+
cleanupPreviousElementState();
38663868
}
38673869
}
38683870
}
@@ -3886,26 +3888,61 @@ function RemoteFunctions(config = {}) {
38863888
const prevDifference = _nodeInfoBox._possDifference;
38873889

38883890
if (Math.abs(calcNewDifference - prevDifference) > 4) {
3889-
dismissUIAndCleanupState();
3891+
dismissNodeInfoBox();
3892+
dismissNodeMoreOptionsBox();
3893+
cleanupPreviousElementState();
38903894
}
38913895
}
38923896
}
38933897
}
38943898
}
38953899
}
38963900

3901+
// this function is responsible to reposition the AI box
3902+
// so we need to reposition it when for ex: a fixed positioned element is selected in the live preview
3903+
// now when live preview is scrolled the element remains at a fixed position but the AI box will drift away
3904+
// so we reposition it when its a fixed element
3905+
function _repositionAIBox() {
3906+
if (!_aiPromptBox || !_aiPromptBox.element) { return; }
3907+
3908+
const aiBox = _aiPromptBox._shadow.querySelector('.phoenix-ai-prompt-box');
3909+
if (!aiBox) { return; }
3910+
3911+
const aiBoxBounds = aiBox.getBoundingClientRect();
3912+
const elementBounds = _aiPromptBox.element.getBoundingClientRect();
3913+
3914+
// this is to store the prev value, so that we can compare it the second time
3915+
if(!_aiPromptBox._possDifference) {
3916+
_aiPromptBox._possDifference = aiBoxBounds.top - elementBounds.top;
3917+
} else {
3918+
const calcNewDifference = aiBoxBounds.top - elementBounds.top;
3919+
const prevDifference = _aiPromptBox._possDifference;
3920+
3921+
// 4 is just for pixelated differences
3922+
if (Math.abs(calcNewDifference - prevDifference) > 4) {
3923+
const boxPositions = _aiPromptBox._getBoxPosition(aiBoxBounds.width, aiBoxBounds.height);
3924+
3925+
aiBox.style.left = boxPositions.leftPos + 'px';
3926+
aiBox.style.top = boxPositions.topPos + 'px';
3927+
_aiPromptBox._possDifference = calcNewDifference;
3928+
}
3929+
}
3930+
}
3931+
38973932
function _scrollHandler(e) {
38983933
// Document scrolls can be updated immediately. Any other scrolls
38993934
// need to be updated on a timer to ensure the layout is correct.
39003935
if (e.target === window.document) {
39013936
redrawHighlights();
39023937
// need to dismiss the box if the elements are fixed, otherwise they drift at times
39033938
_dismissBoxesForFixedElements();
3939+
_repositionAIBox(); // and reposition the AI box
39043940
} else {
39053941
if (_localHighlight || _clickHighlight || _hoverHighlight) {
39063942
window.setTimeout(redrawHighlights, 0);
39073943
}
39083944
_dismissBoxesForFixedElements();
3945+
_repositionAIBox();
39093946
}
39103947
}
39113948

0 commit comments

Comments
 (0)