uiwjs / uiwjs/react-codemirror
Bug: Undo History Not Working for Accept Changes in UnifiedMergeView
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Description
When using unifiedMergeView with mergeControls: true, the undo history functionality (Ctrl+Z/Cmd+Z) only works for rejected changes but not for accepted changes. The expected behavior is that both accept and reject operations should be undoable.
Steps to Reproduce
- Create a basic setup with
unifiedMergeView:
"use client";
import React, { useEffect, useRef } from "react";
import { EditorView, keymap } from "@codemirror/view";
import { unifiedMergeView } from "@codemirror/merge";
import { javascript } from "@codemirror/lang-javascript";
import { oneDark } from "@codemirror/theme-one-dark";
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
export default function DemoMergeIssue() {
const editorRef = useRef(null);
const commonExtensions = [
javascript({ jsx: true, typescript: true }),
oneDark,
history(),
keymap.of(defaultKeymap),
keymap.of(historyKeymap),
];
useEffect(() => {
if (editorRef.current) {
// Create a unified merge view.
const view = new EditorView({
doc: "console.log('Modified Code');",
extensions: [
...commonExtensions,
oneDark,
javascript(),
unifiedMergeView({
original: "console.log('Original Code');",
highlightChanges: true,
mergeControls: true,
}),
],
parent: editorRef.current,
});
return () => view.destroy();
}
}, []);
return (
<div
ref={editorRef}
style={{
height: "400px",
border: "1px solid #ccc",
borderRadius: "4px",
margin: "1rem 0",
}}
/>
);
}
});
- Click the "Accept" button in merge controls
- Try to undo the accept operation with
Ctrl+Z/Cmd+Z - Expected: Changes are undone, Actual: Nothing happens
- Click the "Reject" button in merge controls
- Try to undo the reject operation with
Ctrl+Z/Cmd+Z - Expected: Changes are undone, Actual: Changes are undone successfully
Analysis
The issue appears to be related to how the unified merge view handles history states for accept operations. While reject operations properly integrate with the history extension, accept operations seem to bypass the history mechanism.
Environment
"@codemirror/commands": "^6.8.0",
"@codemirror/lang-javascript": "^6.2.3",
"@codemirror/merge": "^6.8.0",
"@codemirror/state": "^6.5.2",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.36.3",
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided unifiedMergeView reproduction with mergeControls and the history extension, then trace how Accept and Reject dispatch their changes. Confirm the behavior against the stated undo expectations and identify the relevant integration point before adding a regression test; done means accepted changes can be undone like rejected changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100