@copilotkit/react-textarea 1.70.1 → 1.70.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-textarea",
3
- "version": "1.70.1",
3
+ "version": "1.70.3",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -59,9 +59,9 @@
59
59
  "slate-history": "^0.93.0",
60
60
  "slate-react": "^0.98.1",
61
61
  "tailwind-merge": "^1.13.2",
62
- "@copilotkit/react-core": "1.70.1",
63
- "@copilotkit/runtime-client-gql": "1.70.1",
64
- "@copilotkit/shared": "1.70.1"
62
+ "@copilotkit/react-core": "1.70.3",
63
+ "@copilotkit/runtime-client-gql": "1.70.3",
64
+ "@copilotkit/shared": "1.70.3"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/lodash.merge": "^4.6.7",
@@ -1,11 +1,12 @@
1
1
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
2
- import { Editor, Location, Transforms } from "slate";
2
+ import type { Editor, Location } from "slate";
3
+ import { Transforms } from "slate";
3
4
  import { ReactEditor, useSlate, useSlateSelection } from "slate-react";
4
5
  import {
5
6
  getFullEditorTextWithNewlines,
6
7
  getTextAroundSelection,
7
8
  } from "../../lib/get-text-around-cursor";
8
- import {
9
+ import type {
9
10
  EditingEditorState,
10
11
  InsertionEditorApiConfig,
11
12
  } from "../../types/base/autosuggestions-bare-function";
@@ -172,8 +173,16 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
172
173
  editorState={editorState(editor, selection)}
173
174
  apiConfig={props.apiConfig}
174
175
  performInsertion={(insertedText) => {
175
- // replace the selection with the inserted text
176
- Transforms.delete(editor, { at: selection });
176
+ // Replace the selection with the inserted text.
177
+ //
178
+ // `insertText` already deletes an expanded range (via point refs)
179
+ // before inserting at its start, and inserts in place when the
180
+ // range is collapsed. Deleting first and then reusing `selection`
181
+ // destroys text: the range is stale after the delete, so the
182
+ // delete inside `insertText` runs again at the same offsets and
183
+ // eats the characters that followed the insertion point. With a
184
+ // collapsed caret, `Transforms.delete` also deletes one character
185
+ // forward, because it resolves a collapsed range to a point.
177
186
  Transforms.insertText(editor, insertedText, {
178
187
  at: selection,
179
188
  });