MCPcopy Create free account
hub / github.com/continuedev/continue / OSRContextMenu

Function OSRContextMenu

gui/src/components/OSRContextMenu.tsx:13–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11}
12
13const OSRContextMenu = () => {
14 const ideMessenger = useContext(IdeMessengerContext);
15 const isOSREnabled = useIsOSREnabled();
16 const platform = useRef(getPlatform());
17
18 const [position, setPosition] = useState<Position | null>(null);
19 const [canCopy, setCanCopy] = useState(false);
20 const [canCut, setCanCut] = useState(false);
21 const [canPaste, setCanPaste] = useState(false);
22
23 const menuRef = React.useRef<HTMLDivElement>(null);
24 const selectedTextRef = useRef<string | null>(null);
25 const selectedRangeRef = useRef<Range | null>(null);
26
27 function onMenuItemClick(
28 event: React.MouseEvent<HTMLDivElement, MouseEvent>,
29 ) {
30 event.preventDefault();
31
32 // restore selection
33 if (selectedRangeRef.current) {
34 const selection = window.getSelection();
35 selection?.removeAllRanges();
36 selection?.addRange(selectedRangeRef.current);
37 }
38
39 // Hide menu
40 setPosition(null);
41 }
42
43 useEffect(() => {
44 function leaveWindowHandler() {
45 setPosition(null);
46 }
47 function contextMenuHandler(event: MouseEvent) {
48 event.preventDefault();
49 }
50 function clickHandler(event: MouseEvent) {
51 // If clicked outside of menu, close menu
52 if (!menuRef.current?.contains(event.target as Node)) {
53 setPosition(null);
54 }
55
56 if (event.button === 2) {
57 // Prevent default context menu
58 event.preventDefault();
59
60 selectedRangeRef.current = null;
61 selectedTextRef.current = null;
62
63 const selection = window.getSelection();
64 let isClickWithinSelection = false;
65 if (selection && selection.rangeCount > 0) {
66 const range = selection.getRangeAt(0);
67 const selectedText = range.toString();
68 selectedRangeRef.current = range.cloneRange();
69
70 if (selectedText.length > 0) {

Callers

nothing calls this directly

Calls 4

getPlatformFunction · 0.90
useIsOSREnabledFunction · 0.85
onMenuItemClickFunction · 0.85
postMethod · 0.65

Tested by

no test coverage detected