Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/visualBuilder/collab.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ export function collabStyles() {
resize: vertical;
border-radius: 4px;
border: 0.0625rem solid #dde3ee;
line-height: 1.375rem;
color: #222222;
padding: 0.5rem 1rem;
max-height: 6.25rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const CommentTextArea: React.FC<ICommentTextAreaProps> = React.memo(
state,
error,
showSuggestions,
cursorPosition,
selectedIndex,
filteredUsers,
inputRef,
Expand Down Expand Up @@ -79,10 +80,16 @@ const CommentTextArea: React.FC<ICommentTextAreaProps> = React.memo(
"collab-thread-body--input--textarea--suggestionsList"
]
)}
// style={{
// left: `${cursorPosition.left}px`,
// top: `${cursorPosition.top}px`,
// }}
style={{
...(cursorPosition.showAbove
? {
bottom: `${window.innerHeight - (inputRef.current?.getBoundingClientRect().top || 0) - cursorPosition.top}px`,
top: "auto",
}
: {
top: `${(inputRef.current?.getBoundingClientRect().top || 0) + cursorPosition.top}px`,
}),
}}
ref={listRef}
>
{filteredUsers.map((user, index) => (
Expand Down
95 changes: 95 additions & 0 deletions src/visualBuilder/generators/generateThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,101 @@ export function updatePopupPositions() {
});
}

export function updateSuggestionListPosition() {
const suggestionLists = document.querySelectorAll(
".collab-thread-body--input--textarea--suggestionsList"
);

if (!suggestionLists.length) return;

suggestionLists.forEach((list) => {
if (!(list instanceof HTMLElement)) return;

const textarea = document.querySelector(
".collab-thread-body--input--textarea"
) as HTMLTextAreaElement | null;

if (!textarea) return;
const positionData = list.getAttribute("data-position");
const parsedData = positionData ? JSON.parse(positionData) : null;
const showAbove = window.getComputedStyle(list).bottom !== "auto";
const textareaRect = textarea.getBoundingClientRect();
if (showAbove) {
const lineHeight =
parseInt(window.getComputedStyle(textarea).lineHeight) || 20;
const paddingTop =
parseInt(window.getComputedStyle(textarea).paddingTop) || 8;
const cursorLineY =
parsedData?.cursorLineY || paddingTop + lineHeight;

list.style.position = "fixed";
list.style.bottom = `${window.innerHeight - textareaRect.top - cursorLineY + lineHeight}px`;
list.style.top = "auto";
} else {
const lineHeight =
parseInt(window.getComputedStyle(textarea).lineHeight) || 20;
const paddingTop =
parseInt(window.getComputedStyle(textarea).paddingTop) || 8;

const cursorLineY =
parsedData?.cursorLineY || paddingTop + lineHeight;

list.style.position = "fixed";
list.style.top = `${textareaRect.top + cursorLineY}px`;
list.style.bottom = "auto";
}

if (!positionData && textareaRect) {
const lineHeight =
parseInt(window.getComputedStyle(textarea).lineHeight) || 20;
const paddingTop =
parseInt(window.getComputedStyle(textarea).paddingTop) || 8;

const positionInfo = {
showAbove: showAbove,
cursorLineY: paddingTop + lineHeight,
};
list.setAttribute("data-position", JSON.stringify(positionInfo));
}

const listRect = list.getBoundingClientRect();

if (!showAbove && listRect.bottom > window.innerHeight) {
const lineHeight =
parseInt(window.getComputedStyle(textarea).lineHeight) || 20;
const paddingTop =
parseInt(window.getComputedStyle(textarea).paddingTop) || 8;
const cursorLineY =
parsedData?.cursorLineY || paddingTop + lineHeight;

list.style.bottom = `${window.innerHeight - textareaRect.top - cursorLineY + lineHeight}px`;
list.style.top = "auto";

if (positionData) {
const updatedData = JSON.parse(positionData);
updatedData.showAbove = true;
list.setAttribute("data-position", JSON.stringify(updatedData));
}
} else if (showAbove && listRect.top < 0) {
const lineHeight =
parseInt(window.getComputedStyle(textarea).lineHeight) || 20;
const paddingTop =
parseInt(window.getComputedStyle(textarea).paddingTop) || 8;
const cursorLineY =
parsedData?.cursorLineY || paddingTop + lineHeight;

list.style.top = `${textareaRect.top + cursorLineY}px`;
list.style.bottom = "auto";

if (positionData) {
const updatedData = JSON.parse(positionData);
updatedData.showAbove = false;
list.setAttribute("data-position", JSON.stringify(updatedData));
}
}
});
}

export function calculatePopupPosition(
button: HTMLElement,
popup: HTMLElement
Expand Down
24 changes: 15 additions & 9 deletions src/visualBuilder/hooks/useCommentTextArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const useCommentTextArea = (
const [state, setState] = useState<ICommentState>(initialState);

const [showSuggestions, setShowSuggestions] = useState(false);
const [cursorPosition, setCursorPosition] = useState({ top: 0, left: 0 });
const [cursorPosition, setCursorPosition] = useState({
top: 0,
left: 0,
showAbove: false,
});
const [searchTerm, setSearchTerm] = useState("");
const [selectedIndex, setSelectedIndex] = useState(0);
const [filteredUsers, setFilteredUsers] = useState<IMentionList[]>([]);
Expand Down Expand Up @@ -223,25 +227,27 @@ export const useCommentTextArea = (
);
document.body.removeChild(span);

const currentLineY = currentLineNumber * lineHeight + paddingTop;
const scrollTop = textarea.scrollTop;
const currentLineY =
currentLineNumber * lineHeight + paddingTop - scrollTop;
const nextLineY = currentLineY + lineHeight;

const viewportHeight = window.innerHeight;
const suggestionsHeight = 160;

const spaceBelow =
viewportHeight -
(textarea.getBoundingClientRect().top + nextLineY);
const textareaRect = textarea.getBoundingClientRect();
const absoluteTop = textareaRect.top + nextLineY;
const spaceBelow = viewportHeight - absoluteTop;
const showAbove = spaceBelow < suggestionsHeight;

const top = showAbove
? currentLineY - suggestionsHeight
: nextLineY;
const top = showAbove ? currentLineY : nextLineY;

return {
top,
left,
showAbove,
absoluteTop,
scrollTop,
currentLineNumber,
};
},
[]
Expand Down
9 changes: 7 additions & 2 deletions src/visualBuilder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ import {
} from "./utils/updateFocussedState";
import { useHighlightCommentIcon } from "./eventManager/useHighlightCommentIcon";
import { updateHighlightedCommentIconPosition } from "./generators/generateHighlightedComment";
import { updateCollabIconPosition } from "./generators/generateThread";
import { updatePopupPositions } from "./generators/generateThread";
import {
updateCollabIconPosition,
updatePopupPositions,
updateSuggestionListPosition,
} from "./generators/generateThread";
import { useRecalculateVariantDataCSLPValues } from "./eventManager/useRecalculateVariantDataCSLPValues";
import { VB_EmptyBlockParentClass } from "..";
import { useCollab } from "./eventManager/useCollab";
Expand Down Expand Up @@ -98,6 +101,7 @@ export class VisualBuilder {
private scrollEventHandler = () => {
updateCollabIconPosition();
updatePopupPositions();
updateSuggestionListPosition();
updateHighlightedCommentIconPosition(); // Update icons position
};

Expand All @@ -108,6 +112,7 @@ export class VisualBuilder {
updateHighlightedCommentIconPosition();
updateCollabIconPosition();
updatePopupPositions();
updateSuggestionListPosition();
if (previousSelectedEditableDOM) {
this.handlePositionChange(
previousSelectedEditableDOM as HTMLElement
Expand Down
Loading