Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function pasteText({replacementText, cursorContext, activeQuery}: {replacementText: string; cursorContext: CursorContext; activeQuery: string;}){
// update text node content with replaced text
const lastIndex = cursorContext.textBeforeCursor.lastIndexOf(activeQuery);
cursorContext.textNode.textContent = cursorContext.textNodeContent.substring(0, lastIndex) + replacementText + cursorContext.textAfterCursor;
const selection = document.getSelection();
if(!selection) return;
// put cursor at the end of the replaced text
const range = document.createRange();
range.setStart(cursorContext.textNode, lastIndex + replacementText.length);
range.setEnd(cursorContext.textNode, lastIndex + replacementText.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment