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) { ...@@ -106,7 +106,7 @@ async function DummyPromise(userInput) {
if (userInput === 'reject') { if (userInput === 'reject') {
reject('Your request could not be processed for now'); reject('Your request could not be processed for now');
} else { } else {
resolve('hello how are you?'); resolve(text);
} }
}, 150); }, 150);
}); });
......
...@@ -15,7 +15,6 @@ const replaceSelectedText = (view, transformedText, replace = false) => { ...@@ -15,7 +15,6 @@ const replaceSelectedText = (view, transformedText, replace = false) => {
const parser = DOMParser.fromSchema(state.config.schema); const parser = DOMParser.fromSchema(state.config.schema);
if (from > state.doc.content.size || to > state.doc.content.size) { if (from > state.doc.content.size || to > state.doc.content.size) {
console.error('Position out of range');
return; return;
} }
...@@ -49,7 +48,8 @@ const replaceSelectedText = (view, transformedText, replace = false) => { ...@@ -49,7 +48,8 @@ const replaceSelectedText = (view, transformedText, replace = false) => {
state = view.state; state = view.state;
// Update the selection to the end of the new text // 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 cursorPosition = paragraphNodes.length !== 0 ? newTo + 2 : newTo;
const newSelection = TextSelection.create( const newSelection = TextSelection.create(
state.doc, state.doc,
......
...@@ -110,8 +110,8 @@ const AskAIOverlay = ({ setPosition, position, config }) => { ...@@ -110,8 +110,8 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
useLayoutEffect(() => { useLayoutEffect(() => {
const WaxSurface = activeView.dom.getBoundingClientRect(); const WaxSurface = activeView.dom.getBoundingClientRect();
const { selection } = activeView.state; const { selection } = activeView.state;
const { from, to } = selection; const { to } = selection;
const start = activeView.coordsAtPos(from); // const start = activeView.coordsAtPos(from);
const end = activeView.coordsAtPos(to - 1); const end = activeView.coordsAtPos(to - 1);
const overLayComponent = document.getElementById('ai-overlay'); const overLayComponent = document.getElementById('ai-overlay');
...@@ -146,8 +146,12 @@ const AskAIOverlay = ({ setPosition, position, config }) => { ...@@ -146,8 +146,12 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
}; };
const handleSubmit = async () => { const handleSubmit = async () => {
setIsLoading(true);
const inputValue = inputRef.current.value; const inputValue = inputRef.current.value;
if (inputValue === '') {
inputRef.current.focus();
return;
}
setIsLoading(true);
// Get the highlighted text from the editor // Get the highlighted text from the editor
const { from, to } = activeView.state.selection; 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