()
| 23 | import { AdapterProvider, getOverleafAdapter } from "./adapters"; |
| 24 | |
| 25 | export const Main = () => { |
| 26 | const { inputRef, setActiveTab } = useConversationUiStore(); |
| 27 | const { |
| 28 | lastSelectedText, |
| 29 | lastSurroundingText, |
| 30 | lastSelectionRange, |
| 31 | setLastSelection, |
| 32 | setSelectedText, |
| 33 | setSurroundingText, |
| 34 | setSelectionRange, |
| 35 | clearOverleafSelection, |
| 36 | } = useSelectionStore(); |
| 37 | const [menuElement, setMenuElement] = useState<Element | null>(null); |
| 38 | const { isOpen, setIsOpen } = useConversationUiStore(); |
| 39 | const { settings, loadSettings, initLocalSettings } = useSettingStore(); |
| 40 | const { login } = useAuthStore(); |
| 41 | const { loadPrompts } = usePromptLibraryStore(); |
| 42 | |
| 43 | useThemeSync(); |
| 44 | |
| 45 | useEffect(() => { |
| 46 | apiclient.updateBaseURL(getEndpointFromLocalStorage(), "v1"); |
| 47 | apiclientV2.updateBaseURL(getEndpointFromLocalStorage(), "v2"); |
| 48 | initLocalSettings(); |
| 49 | login(); |
| 50 | loadSettings(); |
| 51 | loadPrompts(); |
| 52 | }, []); // eslint-disable-line react-hooks/exhaustive-deps |
| 53 | |
| 54 | useEffect(() => { |
| 55 | const handleSelectionChange = () => { |
| 56 | const selection = window.getSelection(); |
| 57 | // check if the selection is in the editor |
| 58 | const editor = document.querySelector(".cm-editor"); |
| 59 | if (editor && editor.contains(selection?.anchorNode ?? null)) { |
| 60 | const text = selection?.toString() ?? null; |
| 61 | |
| 62 | let surrounding = ""; |
| 63 | try { |
| 64 | const cmContentElement = document.querySelector(".cm-content"); |
| 65 | if (cmContentElement) { |
| 66 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 67 | const state = (cmContentElement as any).cmView.view.state; |
| 68 | if (state) { |
| 69 | const cmSelection = state.selection.main; |
| 70 | const doc = state.doc; |
| 71 | const before = doc.sliceString(Math.max(0, cmSelection.from - 100), cmSelection.from); |
| 72 | const after = doc.sliceString(cmSelection.to, Math.min(doc.length, cmSelection.to + 100)); |
| 73 | surrounding = `${before}[SELECTED_TEXT_START]${text}[SELECTED_TEXT_END]${after}`; |
| 74 | } |
| 75 | } |
| 76 | } catch { |
| 77 | // fallback |
| 78 | } |
| 79 | |
| 80 | setLastSelection(text, surrounding, selection?.getRangeAt(0) ?? null); |
| 81 | return; |
| 82 | } else { |
nothing calls this directly
no test coverage detected