-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove State and add Overleaf specific tools
- Loading branch information
1 parent
dcf0d15
commit 429573b
Showing
8 changed files
with
204 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export { retrievers } from "./retriever"; | ||
export { actions } from "./action"; | ||
export { tool, toolName, ToolName } from "./tool"; | ||
export { State } from "./state"; | ||
export { Scope, ToolType, CallerType } from "./enum"; | ||
export * as retriever from "./retriever"; | ||
export * as action from "./action"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
export function insertText(parameters: { | ||
textToInsert: string; | ||
position: 'beginning' | 'end' | 'cursor', | ||
}) { | ||
const { textToInsert, position = 'cursor' } = parameters; | ||
|
||
if (position === "beginning") { | ||
const editorElement = document.querySelector(".cm-content"); | ||
if (editorElement) { | ||
const textNode = document.createTextNode(textToInsert); | ||
editorElement.prepend(textNode); | ||
|
||
// Scroll to bottom | ||
const scroller = document.querySelector(".cm-scroller"); | ||
if (scroller) { | ||
scroller.scrollTo({ top: 0, behavior: "smooth" }); | ||
} | ||
} | ||
} | ||
else if (position === 'end') { | ||
const editorElement = document.querySelector(".cm-content"); | ||
if (editorElement) { | ||
const textNode = document.createTextNode(textToInsert); | ||
editorElement.appendChild(textNode); | ||
|
||
// Scroll to start | ||
const scroller = document.querySelector(".cm-scroller"); | ||
if (scroller) { | ||
scroller.scrollTo({ top: scroller.scrollHeight, behavior: "smooth" }); | ||
} | ||
} | ||
} else if (position === "cursor") { | ||
const selection = window.getSelection(); | ||
|
||
if (!selection?.rangeCount) { | ||
console.error("No cursor location available"); | ||
return; | ||
} | ||
|
||
// Get the range of the current selection or cursor position | ||
const range = selection.getRangeAt(0); | ||
|
||
// Extract the currently selected content (if any) | ||
const selectedContent = range.cloneContents(); | ||
|
||
// Create a document fragment to hold the new content | ||
const fragment = document.createDocumentFragment(); | ||
|
||
// Create a text node for the text to insert before the selection | ||
if (textToInsert) { | ||
fragment.appendChild(document.createTextNode(textToInsert)); | ||
} | ||
|
||
// Append the selected content to the fragment | ||
if (selectedContent) { | ||
fragment.appendChild(selectedContent); | ||
} | ||
|
||
// Insert the fragment into the range | ||
range.deleteContents(); // Remove the current selection | ||
range.insertNode(fragment); | ||
|
||
// Move the cursor to the end of the inserted content | ||
range.collapse(false); // Collapse the range to its end | ||
|
||
// Clear the selection and set the updated range | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export function getEditorContext() { | ||
// Identify the contenteditable container | ||
const contentEditableElement = document.querySelector('.cm-content'); | ||
|
||
if (!contentEditableElement) { | ||
console.error('Editable area not found.'); | ||
return null; | ||
} | ||
|
||
// Get the selection object | ||
const selection = window.getSelection(); | ||
|
||
if (!selection?.rangeCount) { | ||
console.warn('No selection or cursor found.'); | ||
return null; | ||
} | ||
|
||
// Get the active range (selection or cursor position) | ||
const range = selection.getRangeAt(0); | ||
|
||
// Check if the selection is within the editable area | ||
if (!contentEditableElement.contains(range.startContainer)) { | ||
console.warn('Selection is outside the editable area.'); | ||
return null; | ||
} | ||
|
||
// Get the selected text (if any) | ||
const selectedText = selection.toString(); | ||
|
||
// Get text content before the cursor/selection | ||
const beforeCursorRange = document.createRange(); | ||
beforeCursorRange.setStart(contentEditableElement, 0); | ||
beforeCursorRange.setEnd(range.startContainer, range.startOffset); | ||
const textBeforeCursor = beforeCursorRange.toString(); | ||
|
||
// Get text content after the cursor/selection | ||
const afterCursorRange = document.createRange(); | ||
afterCursorRange.setStart(range.endContainer, range.endOffset); | ||
afterCursorRange.setEnd(contentEditableElement, contentEditableElement.childNodes.length); | ||
const textAfterCursor = afterCursorRange.toString(); | ||
|
||
return { | ||
selectedText: selectedText, | ||
textBeforeCursor: textBeforeCursor, | ||
textAfterCursor: textAfterCursor, | ||
cursorPosition: range.startOffset // Cursor offset in the start container | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.