Skip to content
Snippets Groups Projects
Commit 2d40a920 authored by chris's avatar chris
Browse files

fix selection

parent 543d9bee
No related branches found
No related tags found
1 merge request!493Fix ai
......@@ -106,7 +106,7 @@ async function DummyPromise(userInput) {
if (userInput === 'reject') {
reject('Your request could not be processed for now');
} else {
resolve('hello how are you?');
resolve(text);
}
}, 150);
});
......
......@@ -15,7 +15,6 @@ const replaceSelectedText = (view, transformedText, replace = false) => {
const parser = DOMParser.fromSchema(state.config.schema);
if (from > state.doc.content.size || to > state.doc.content.size) {
console.error('Position out of range');
return;
}
......@@ -49,7 +48,8 @@ const replaceSelectedText = (view, transformedText, replace = false) => {
state = view.state;
// Update the selection to the end of the new text
const newTo = from + transformedText.length;
const newFrom = replace ? from : to;
const newTo = newFrom + transformedText.length;
const cursorPosition = paragraphNodes.length !== 0 ? newTo + 2 : newTo;
const newSelection = TextSelection.create(
state.doc,
......
......@@ -110,8 +110,8 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
useLayoutEffect(() => {
const WaxSurface = activeView.dom.getBoundingClientRect();
const { selection } = activeView.state;
const { from, to } = selection;
const start = activeView.coordsAtPos(from);
const { to } = selection;
// const start = activeView.coordsAtPos(from);
const end = activeView.coordsAtPos(to - 1);
const overLayComponent = document.getElementById('ai-overlay');
......@@ -146,8 +146,12 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
};
const handleSubmit = async () => {
setIsLoading(true);
const inputValue = inputRef.current.value;
if (inputValue === '') {
inputRef.current.focus();
return;
}
setIsLoading(true);
// Get the highlighted text from the editor
const { from, to } = activeView.state.selection;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment