Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Bug: Undo History Not Working for Accept Changes in UnifiedMergeView

未关闭
#714 0 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
react, typescript
领域
frontend

调研方向

首先运行提供的、使用 mergeControls 和 history extension 的 unifiedMergeView 复现,然后跟踪 Accept 和 Reject 如何 dispatch 它们的更改。根据所述的 undo 预期确认行为,并在添加回归测试之前确定相关的集成点;完成的标准是接受的更改可以像拒绝的更改一样被 undo。

由索引模型根据 Issue 内容生成。

描述

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

  1. 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",
      }}
    />
  );
}
});
  1. Click the "Accept" button in merge controls
  2. Try to undo the accept operation with Ctrl+Z/Cmd+Z
  3. Expected: Changes are undone, Actual: Nothing happens
  4. Click the "Reject" button in merge controls
  5. Try to undo the reject operation with Ctrl+Z/Cmd+Z
  6. 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",
主要语言
TypeScript
星标
2.3k
派生
162
平均合并
2 小时 41 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uiwjs/react-codemirror 的其他 Issue

查看 uiwjs/react-codemirror 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。