💄 replace text in input box
This commit is contained in:
parent
9fdbefd889
commit
5a956fc35c
2 changed files with 26 additions and 2 deletions
|
|
@ -30,7 +30,10 @@ import useHistory from "../../hooks/useHistory";
|
|||
import useUpdatingRef from "../../hooks/useUpdatingRef";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { defaultModelSelector } from "../../redux/selectors/modelSelectors";
|
||||
import { setEditingContextItemAtIndex } from "../../redux/slices/stateSlice";
|
||||
import {
|
||||
consumeMainEditorContent,
|
||||
setEditingContextItemAtIndex,
|
||||
} from "../../redux/slices/stateSlice";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { isMetaEquivalentKeyPressed } from "../../util";
|
||||
import { isJetBrains, postToIde } from "../../util/ide";
|
||||
|
|
@ -231,6 +234,10 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const mainEditorContent = useSelector(
|
||||
(store: RootState) => store.state.mainEditorContent,
|
||||
);
|
||||
|
||||
const editor: Editor = useEditor({
|
||||
extensions: [
|
||||
Document,
|
||||
|
|
@ -311,7 +318,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
style: "font-size: 14px;",
|
||||
},
|
||||
},
|
||||
content: props.editorState || "",
|
||||
content: props.editorState || mainEditorContent || "",
|
||||
onUpdate: ({ editor, transaction }) => {
|
||||
// If /edit is typed and no context items are selected, select the first
|
||||
|
||||
|
|
@ -350,6 +357,13 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (mainEditorContent && editor) {
|
||||
editor.commands.setContent(mainEditorContent);
|
||||
dispatch(consumeMainEditorContent());
|
||||
}
|
||||
}, [mainEditorContent, editor]);
|
||||
|
||||
const onEnterRef = useUpdatingRef(
|
||||
(modifiers: InputModifiers) => {
|
||||
const json = editor.getJSON();
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ type State = {
|
|||
title: string;
|
||||
sessionId: string;
|
||||
defaultModelTitle: string;
|
||||
mainEditorContent?: JSONContent;
|
||||
};
|
||||
|
||||
const initialState: State = {
|
||||
|
|
@ -187,8 +188,16 @@ export const stateSlice = createSlice({
|
|||
state.active = true;
|
||||
},
|
||||
clearLastResponse: (state) => {
|
||||
if (state.history.length < 2) {
|
||||
return;
|
||||
}
|
||||
state.mainEditorContent =
|
||||
state.history[state.history.length - 2].editorState;
|
||||
state.history = state.history.slice(0, -2);
|
||||
},
|
||||
consumeMainEditorContent: (state) => {
|
||||
state.mainEditorContent = undefined;
|
||||
},
|
||||
setContextItemsAtIndex: (
|
||||
state,
|
||||
{
|
||||
|
|
@ -496,5 +505,6 @@ export const {
|
|||
initNewActiveMessage,
|
||||
setMessageAtIndex,
|
||||
clearLastResponse,
|
||||
consumeMainEditorContent,
|
||||
} = stateSlice.actions;
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue