diff --git a/editors/demo/src/Editoria/config/config.js b/editors/demo/src/Editoria/config/config.js index 81440af1627bdceea4e5144c791151177adadc97..3c828db6d88f2261ab5daefe9f24aba7e2f465b5 100644 --- a/editors/demo/src/Editoria/config/config.js +++ b/editors/demo/src/Editoria/config/config.js @@ -108,7 +108,7 @@ async function DummyPromise(userInput) { } else { resolve(text); } - }, 4150); + }, 150); }); } diff --git a/wax-prosemirror-services/src/AiService/InsertTextBelowSelection.js b/wax-prosemirror-services/src/AiService/InsertTextBelowSelection.js deleted file mode 100644 index 5d14eea5b397180a53f8853b3cdc137fdaf26f35..0000000000000000000000000000000000000000 --- a/wax-prosemirror-services/src/AiService/InsertTextBelowSelection.js +++ /dev/null @@ -1,42 +0,0 @@ -import { TextSelection } from 'prosemirror-state'; - -const insertTextBelowSelection = (view, transformedText) => { - let { state } = view; - let { tr } = state; - - const { to } = tr.selection; - - // Check if 'to' is within the document size - if (to > state.doc.content.size) { - console.error('Position out of range'); - return; - } - - // Fetch the most recent state again - state = view.state; - - // Create a new paragraph node with the transformed text - const paragraph = state.schema.nodes.paragraph.create( - {}, - state.schema.text(transformedText), - ); - - // Insert the new paragraph node below the selection - tr = tr.insert(to + 1, paragraph); - - // Dispatch the transaction to update the state - view.dispatch(tr); - - // Fetch the most recent state again - state = view.state; - - // Update the selection to the end of the new text - const newTo = to + transformedText.length + 1; // +1 for the paragraph node - const newSelection = TextSelection.create(state.doc, newTo, newTo); - tr = state.tr.setSelection(newSelection); - - // Dispatch the final transaction to update the state - view.dispatch(tr); -}; - -export default insertTextBelowSelection; diff --git a/wax-prosemirror-services/src/AiService/ReplaceSelectedText.js b/wax-prosemirror-services/src/AiService/ReplaceSelectedText.js index 315f96ea7fe209640739718bcc35bf64154f32a3..0cb31337c5933c90c2a381254b7f75b5bf3a67cf 100644 --- a/wax-prosemirror-services/src/AiService/ReplaceSelectedText.js +++ b/wax-prosemirror-services/src/AiService/ReplaceSelectedText.js @@ -2,6 +2,7 @@ import { DOMParser } from 'prosemirror-model'; import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'; import { Selection, TextSelection } from 'prosemirror-state'; +// To Do keep soft break const elementFromString = string => { const wrappedValue = `<body>${string}</body>`; @@ -33,22 +34,12 @@ const replaceSelectedText = (view, transformedText) => { if (transformedText.includes('\n\n')) { transformedText.split('\n\n').forEach(element => { paragraphNodes.push( - state.schema.nodes.paragraph.create( - { - preserveWhitespace: 'full', - }, - state.schema.text(element), - ), + state.schema.nodes.paragraph.create({}, state.schema.text(element)), ); }); } - const newText = state.schema.nodes.paragraph.create( - { - preserveWhitespace: 'full', - }, - state.schema.text(transformedText), - ); + const newText = state.schema.text(transformedText); const finalReplacementText = paragraphNodes.length !== 0 ? paragraphNodes : newText; diff --git a/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js b/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js index bf35643618d3ed83d3b9f6a00e2350575d5d3e47..1b92a26a056465b0ffdd3b6d042a2409d0a408d8 100644 --- a/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js +++ b/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js @@ -3,7 +3,6 @@ import React, { useRef, useLayoutEffect, useContext, useState } from 'react'; import styled from 'styled-components'; import { WaxContext, icons } from 'wax-prosemirror-core'; import replaceSelectedText from '../ReplaceSelectedText'; -import insertTextBelowSelection from '../InsertTextBelowSelection'; const Wrapper = styled.div` display: flex; @@ -143,7 +142,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => { }; const handleInsertTextBelow = () => { - insertTextBelowSelection(activeView, result); + replaceSelectedText(activeView, result); }; const handleSubmit = async () => {