Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/mean-moles-poke.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/tough-deers-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-editor": patch
---

Reverting Editor Cursor Bouncing Fix
23 changes: 18 additions & 5 deletions packages/perseus-editor/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type State = {
// eslint-disable-next-line react/no-unsafe
class Editor extends React.Component<Props, State> {
lastUserValue: string | null | undefined;
deferredChange: any | null | undefined;
widgetIds: any | null | undefined;

underlay = React.createRef<HTMLDivElement>();
Expand Down Expand Up @@ -250,6 +251,12 @@ class Editor extends React.Component<Props, State> {
}
}

componentWillUnmount() {
// TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
// eslint-disable-next-line no-restricted-syntax
clearTimeout(this.deferredChange);
}

getWidgetEditor(
id: string,
type: PerseusWidget["type"],
Expand Down Expand Up @@ -434,11 +441,17 @@ class Editor extends React.Component<Props, State> {
handleChange: (e: React.SyntheticEvent<HTMLTextAreaElement>) => void = (
e: React.SyntheticEvent<HTMLTextAreaElement>,
) => {
const newValue = e.currentTarget.value;
this.setState({textAreaValue: newValue});
if (newValue !== this.props.content) {
this.props.onChange({content: newValue});
}
// TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
// eslint-disable-next-line no-restricted-syntax
clearTimeout(this.deferredChange);
this.setState({textAreaValue: e.currentTarget.value});
// TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
// eslint-disable-next-line no-restricted-syntax
this.deferredChange = setTimeout(() => {
if (this.state.textAreaValue !== this.props.content) {
this.props.onChange({content: this.state.textAreaValue});
}
}, this.props.apiOptions.editorChangeDelay);
};

_handleKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void = (
Expand Down
Loading