Skip to content
Closed
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions src/components/CodeSelectionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const CodeSelectionMenu: React.FC<CodeSelectionMenuProps> = ({
ref={menuRef}
className="twp fixed bg-white border border-gray-300 rounded-lg shadow-lg py-1 z-50 flex"
style={{
left: Math.max(10, Math.min(225, window.innerWidth - 150)),
left: Math.max(10, Math.min(position.x, window.innerWidth - 150)),
top: Math.max(10, Math.min(position.y, window.innerHeight - 50)),
minWidth: '120px'
}}
Expand Down Expand Up @@ -260,23 +260,26 @@ export const useCodeSelection = (editorType: 'markdown' | 'concerto' | 'json') =
if (selection && !selection.isEmpty()) {
const selectedText = editor.getModel()?.getValueInRange(selection).trim();
if (selectedText && selectedText.length > 0) {
const position = editor.getScrolledVisiblePosition(selection.getStartPosition());
const startPosition = editor.getScrolledVisiblePosition(selection.getStartPosition());
const endPosition = editor.getScrolledVisiblePosition(selection.getEndPosition());
const editorContainer = editor.getDomNode()?.closest('.editorwrapper');
const editorRect = editorContainer?.getBoundingClientRect();

Comment thread
ML-dev-crypto marked this conversation as resolved.
let x: number, y: number;

if (editorRect && position) {
x = Math.max(editorRect.left + 20, Math.min(position.left, editorRect.right - 150));
y = Math.max(editorRect.top + 20, Math.min(position.top, editorRect.bottom - 50));
if (!startPosition || !endPosition) {
return;
}

if (editorRect) {
x = Math.max(editorRect.left + 20, Math.min(editorRect.left + startPosition.left, editorRect.right - 150));
y = Math.max(editorRect.top + 20, Math.min(editorRect.top + endPosition.top - 40, editorRect.bottom - 50));

x = Math.max(10, Math.min(x, window.innerWidth - 150));
y = Math.max(10, Math.min(y, window.innerHeight - 50));
} else if (position) {
x = Math.max(10, Math.min(position.left, window.innerWidth - 150));
y = Math.max(10, Math.min(position.top, window.innerHeight - 50));
} else {
return;
x = Math.max(10, Math.min(startPosition.left, window.innerWidth - 150));
y = Math.max(10, Math.min(endPosition.top - 40, window.innerHeight - 50));
}
Comment thread
ML-dev-crypto marked this conversation as resolved.

setSelectedText(selectedText);
Expand Down
Loading