Skip to content

Commit ff87685

Browse files
committed
fix: move boxes to down when no space at top
1 parent e3bf8f1 commit ff87685

File tree

1 file changed

+11
-66
lines changed

1 file changed

+11
-66
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 11 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -394,71 +394,6 @@ function RemoteFunctions(config) {
394394
delete window._currentDraggedElement;
395395
}
396396

397-
/**
398-
* This function is to calculate the width of the info box based on the number of chars in the box
399-
* @param {String} tagName - the element's tag name
400-
* @param {String} id - the element's id
401-
* @param {Array} classes - the array of class names
402-
* @returns {Number} - the total char count
403-
*/
404-
function _calculateInfoBoxCharCount(tagName, id, classes) {
405-
// char count for tag name
406-
let tagNameCharCount = tagName.length;
407-
let idNameCharCount = 0;
408-
let classNameCharCount = 0;
409-
// char count for id
410-
if (id) {
411-
idNameCharCount = id.length + 1; // +1 for #
412-
}
413-
414-
// char count for classes
415-
if (classes.length > 0) {
416-
for (let i = 0; i < Math.min(classes.length, 3); i++) {
417-
classNameCharCount += classes[i].length + 1; // +1 for .
418-
}
419-
420-
if (classes.length > 3) {
421-
// "+ X more" for more than 3 classes
422-
const moreText = `+${classes.length - 3} more`;
423-
classNameCharCount += moreText.length;
424-
}
425-
}
426-
return Math.max(tagNameCharCount, idNameCharCount, classNameCharCount);
427-
}
428-
429-
/**
430-
* This function checks whether there is overlap between the info and the more options box
431-
* @param {Number} elemWidth - the width of the DOM element
432-
* @param {String} tagName - the element's tag name
433-
* @param {String} id - the element's id
434-
* @param {Array} classes - the array of class names
435-
* @returns {Number} - the total char count
436-
*/
437-
function checkOverlap(elemWidth, tagName, id, classes) {
438-
let avgCharWidth = 6;
439-
const basePadding = 16;
440-
441-
// char count for tag name, id, and classes
442-
let charCount = _calculateInfoBoxCharCount(tagName, id, classes);
443-
if(charCount <= 10) {
444-
avgCharWidth = 7.5;
445-
}
446-
447-
// calc estimate width based on the char count
448-
const infoBoxWidth = basePadding + (charCount * avgCharWidth);
449-
450-
// more options box is 106px
451-
const moreOptionsBoxWidth = 106;
452-
453-
// check if there's enough space for both boxes
454-
// 20px buffer for spacing between boxes
455-
if (elemWidth > (infoBoxWidth + moreOptionsBoxWidth + 20)) {
456-
return false; // No overlap
457-
}
458-
459-
return true;
460-
}
461-
462397
/**
463398
* this function is to check if an element should show the edit text option
464399
* it is needed because edit text option doesn't make sense with many elements like images, videos, hr tag etc
@@ -577,6 +512,10 @@ function RemoteFunctions(config) {
577512
let topPos = elemBounds.top - 30 + scrollTop;
578513
let leftPos = elemBounds.right - boxWidth + scrollLeft;
579514

515+
if (elemBounds.top - 30 < 0) {
516+
topPos = elemBounds.top + elemBounds.height + 5 + scrollTop;
517+
}
518+
580519
return {topPos: topPos, leftPos: leftPos};
581520
},
582521

@@ -769,9 +708,15 @@ function RemoteFunctions(config) {
769708
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
770709
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
771710

772-
let topPos = elemBounds.top - this._calcHeight() + scrollTop;
711+
const boxHeight = this._calcHeight();
712+
713+
let topPos = elemBounds.top - boxHeight + scrollTop;
773714
let leftPos = elemBounds.left + scrollLeft;
774715

716+
if (elemBounds.top - boxHeight < 0) {
717+
topPos = elemBounds.top + elemBounds.height + 5 + scrollTop;
718+
}
719+
775720
return {topPos: topPos, leftPos: leftPos};
776721
},
777722

0 commit comments

Comments
 (0)