Skip to content
Merged
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
1 change: 0 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ The library provides three main editor components in `/src/`:
### Dependencies
- **ace-builds** - Modern Ace editor (replaces legacy brace)
- **diff-match-patch** - Powers diff editor functionality
- **lodash.get**, **lodash.isequal** - Minimal lodash utilities
- **prop-types** - Runtime type checking for older React versions

## Development Notes
Expand Down
51 changes: 10 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
"@testing-library/react": "^16.2.0",
"@types/chai": "^4.3.14",
"@types/diff-match-patch": "^1.0.36",
"@types/lodash": "^4.17.0",
"@types/lodash.get": "^4.4.9",
"@types/lodash.isequal": "^4.5.8",
"@types/node": "^22.5.5",
"@types/prop-types": "^15.7.12",
"@types/react": "^19.0.8",
Expand Down Expand Up @@ -73,8 +70,7 @@
"dependencies": {
"ace-builds": "^1.36.3",
"diff-match-patch": "^1.0.5",
"lodash.get": "^4.4.2",
"lodash.isequal": "^4.5.0",
"fast-equals": "^5.3.3",
"prop-types": "^15.8.1"
},
"husky": {
Expand Down
13 changes: 8 additions & 5 deletions src/ace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as AceBuilds from "ace-builds";
import * as PropTypes from "prop-types";
import * as React from "react";

import isEqual from "lodash.isequal";
import { deepEqual } from "fast-equals";

import {
debounce,
Expand Down Expand Up @@ -415,22 +415,25 @@ export default class ReactAce extends React.Component<IAceEditorProps> {
if (nextProps.showGutter !== oldProps.showGutter) {
this.editor.renderer.setShowGutter(nextProps.showGutter);
}
if (!isEqual(nextProps.setOptions, oldProps.setOptions)) {
if (!deepEqual(nextProps.setOptions, oldProps.setOptions)) {
this.handleOptions(nextProps);
}
// if the value or annotations changed, set the annotations
// changing the value may create create a new session which will require annotations to be re-set
if (valueChanged || !isEqual(nextProps.annotations, oldProps.annotations)) {
if (
valueChanged ||
!deepEqual(nextProps.annotations, oldProps.annotations)
) {
this.editor.getSession().setAnnotations(nextProps.annotations || []);
}
const oldMarkers = oldProps.markers || [];
const nextMarkers = nextProps.markers || [];
if (!isEqual(oldMarkers, nextMarkers)) {
if (!deepEqual(oldMarkers, nextMarkers)) {
this.handleMarkers(nextMarkers);
}

// this doesn't look like it works at all....
if (!isEqual(nextProps.scrollMargin, oldProps.scrollMargin)) {
if (!deepEqual(nextProps.scrollMargin, oldProps.scrollMargin)) {
this.handleScrollMargins(nextProps.scrollMargin);
}

Expand Down
29 changes: 14 additions & 15 deletions src/split.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { Ace, Range } from "ace-builds"; // oxlint-disable-line
import { Split } from "ace-builds/src-noconflict/ext-split";
import * as PropTypes from "prop-types";
import * as React from "react";
import isEqual from "lodash.isequal";
import get from "lodash.get";
import { deepEqual } from "fast-equals";
import {
IAceEditor,
IAceOptions,
Expand Down Expand Up @@ -242,8 +241,8 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
for (let i = 0; i < editorProps.length; i++) {
editor[editorProps[i]] = this.props.editorProps[editorProps[i]];
}
const defaultValueForEditor = get(defaultValue, index);
const valueForEditor = get(value, index, "");
const defaultValueForEditor = defaultValue?.[index];
const valueForEditor = value?.[index] ?? "";
editor.session.setUndoManager(new ace.UndoManager());
editor.setTheme(`ace/theme/${theme}`);
editor.renderer.setScrollMargin(
Expand Down Expand Up @@ -274,8 +273,8 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
: defaultValueForEditor,
cursorStart
);
const newAnnotations = get(annotations, index, []);
const newMarkers = get(markers, index, []);
const newAnnotations = annotations?.[index] ?? [];
const newMarkers = markers?.[index] ?? [];
editor.getSession().setAnnotations(newAnnotations);
if (newMarkers && newMarkers.length > 0) {
this.handleMarkers(newMarkers, editor);
Expand All @@ -287,7 +286,7 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
editor.setOption(option as any, this.props[option]);
} else if (this.props[option]) {
console.warn(
`ReaceAce: editor option ${option} was activated but not found. Did you need to import a related tool or did you possibly mispell the option?`
`ReactAce: editor option ${option} was activated but not found. Did you need to import a related tool or did you possibly misspell the option?`
);
}
}
Expand Down Expand Up @@ -374,10 +373,10 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
editor.setOption(option as any, nextProps[option]);
}
}
if (!isEqual(nextProps.setOptions, oldProps.setOptions)) {
if (!deepEqual(nextProps.setOptions, oldProps.setOptions)) {
this.handleOptions(nextProps, editor);
}
const nextValue = get(nextProps.value, index, "");
const nextValue = nextProps.value?.[index] ?? "";
if (editor.getValue() !== nextValue) {
// editor.setValue is a synchronous function call, change event is emitted before setValue return.
this.silent = true;
Expand All @@ -386,15 +385,15 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
(editor.session.selection as any).fromJSON(pos);
this.silent = false;
}
const newAnnotations = get(nextProps.annotations, index, []);
const oldAnnotations = get(oldProps.annotations, index, []);
if (!isEqual(newAnnotations, oldAnnotations)) {
const newAnnotations = nextProps.annotations?.[index] ?? [];
const oldAnnotations = oldProps.annotations?.[index] ?? [];
if (!deepEqual(newAnnotations, oldAnnotations)) {
editor.getSession().setAnnotations(newAnnotations);
}

const newMarkers = get(nextProps.markers, index, []);
const oldMarkers = get(oldProps.markers, index, []);
if (!isEqual(newMarkers, oldMarkers) && Array.isArray(newMarkers)) {
const newMarkers = nextProps.markers?.[index] ?? [];
const oldMarkers = oldProps.markers?.[index] ?? [];
if (!deepEqual(newMarkers, oldMarkers) && Array.isArray(newMarkers)) {
this.handleMarkers(newMarkers, editor);
}
});
Expand Down
Loading