Skip to content

Commit 924e2f3

Browse files
authored
Merge pull request #251 from eccenca/fix/uriPatternEditor-CMEM-6461
Fix: Code editor sets initial value on every code editor instance re-init
2 parents e2bb749 + dbb2916 commit 924e2f3

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88

99
### Added
1010

11-
- Added custom icon for "Concatenate to file" operator (CMEM-6476).
12-
- `CntentGroup` component
11+
- Added custom icon for "Concatenate to file" operator (CMEM-6476).
12+
- `<ContentGroup />` component
1313
- Manage display of a grouped content section.
1414
- Add info, actions and context annotations by using its properties.
1515
- Can be nested into each other.
@@ -19,7 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1919
- editor is focused on load if `autoFocus` prop is set to `true`
2020
- implemented support for `disabled` state in code editor
2121
- implemented support for `intent` states in code editor
22-
- `Label` component
22+
- `<Label />`
2323
- added `additionalElements` property to display elements at the end of the label
2424
- `<NodeContent />`
2525
- `resizeDirections` to specifiy the axis that can be used to resize the node
@@ -31,6 +31,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
3131
- `<MenutItem />`
3232
- `tooltip` property to dislay tooltip on menu item label
3333

34+
### Fixed
35+
36+
- `CodeAutocompleteField`:
37+
- Code editor resets to initial value on every code editor instance re-init
38+
3439
### Changed
3540

3641
- StickyNote data structure: Refactored position and dimension (breaking change)

src/components/AutoSuggestion/AutoSuggestion.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ const AutoSuggestion = ({
219219
CodeAutocompleteFieldSuggestionWithReplacementInfo | undefined
220220
>(undefined);
221221
const [cm, setCM] = React.useState<EditorView>();
222+
const currentCm = React.useRef<EditorView>()
223+
currentCm.current = cm
222224
const isFocused = React.useRef(false);
223225
const autoSuggestionDivRef = React.useRef<HTMLDivElement>(null);
224226
/** Mutable editor state, since this needs to be current in scope of the SingleLineEditorComponent. */
@@ -235,12 +237,12 @@ const AutoSuggestion = ({
235237
const pathIsValid = validationResponse?.valid ?? true;
236238

237239
React.useEffect(() => {
238-
if (reInitOnInitialValueChange && initialValue != null && cm) {
240+
if (reInitOnInitialValueChange && initialValue != null && currentCm.current) {
239241
dispatch({
240-
changes: { from: 0, to: cm?.state?.doc.length, insert: initialValue },
242+
changes: { from: 0, to: currentCm.current.state?.doc.length, insert: initialValue },
241243
});
242244
}
243-
}, [initialValue, cm, reInitOnInitialValueChange]);
245+
}, [initialValue, reInitOnInitialValueChange]);
244246

245247
const setCurrentIndex = (newIndex: number) => {
246248
editorState.index = newIndex;

0 commit comments

Comments
 (0)