Skip to content

feat: add cut and undo#74

Closed
foxmaybeOI1761640545 wants to merge 4 commits intozmrlft:mainfrom
foxmaybeOI1761640545:feat/add-cut-and-undo
Closed

feat: add cut and undo#74
foxmaybeOI1761640545 wants to merge 4 commits intozmrlft:mainfrom
foxmaybeOI1761640545:feat/add-cut-and-undo

Conversation

@foxmaybeOI1761640545
Copy link

@foxmaybeOI1761640545 foxmaybeOI1761640545 commented Dec 16, 2025

使用后想法

有时候将应用默认的字符画到墙上的时候,发现画错位置想修改时就会很麻烦。
既然大佬的GreenWall已经有了“Ctrl+C”和“Ctrl+V”,那我干脆增加了一个“Ctrl+Z”和“Ctrl+X”。

功能总结

  • Ctrl+Z : 实现撤销 (Undo) 功能。
  • Ctrl+X : 实现剪切 (Cut) 功能(仅在复制模式下有效)。

详细说明

Ctrl+Z(撤销)

该功能用于退回上一步的操作(例如,较差、填充等)。

  • 代码位置 : frontend/src/components/ContributionCalendar.tsx (约 924 行)
  • 逻辑说明:
    • 支持撤销的操作:应用字符画、重置重置(Reset)、剪切(Cut)、导入(Import)、完全填充(Fill All)。这些操作执行前都调用了 PushSnapshot() 。
    • 不支持撤销的操作:普通的手动鼠标拖拽张力(画笔/橡皮擦)。这些直接操作状态而未记录快照,修改因此无法通过Ctrl+Z逐笔撤回。

Ctrl+X(剪切)

该功能用于将选定区域的贡献图案复制到剪贴板上,并从日历上清除这些图案。

  • 代码位置 : frontend/src/components/ContributionCalendar.tsx (约第 859 行)
  • 逻辑说明:
    • 触发方式:Ctrl+X + copyMode + 有选区。
    • 验证 : 检查选是否有涂色格子,无则提示。
    • 快照 : 调用pushSnapshot() 保存当前状态。
    • 保存 : 将选区数据存入 SelectionBuffer 。
    • 清晰 : 从用户贡献中剔除的贡献数据。
    • 反馈:弹出Toast提示“剪切成功”,并自动进入粘贴预览模式。

Summary by cubic

Adds Undo (Ctrl+Z) and Cut (Ctrl+X) to the contribution calendar to make editing faster and safer. Also introduces a history hook to manage snapshots and a Windows dev script for easier local runs.

  • New Features

    • Ctrl+Z: Undo for apply character, reset, cut, import, and fill all (not for per-cell pen/eraser dragging).
    • Ctrl+X: Cut in copy mode; copies the selection to buffer, clears those cells, shows a toast, and opens paste preview.
    • useContributionHistory hook with pushSnapshot, undo, and redo to manage contribution state.
    • Windows dev (run.bat) and packaging (build_release.bat) scripts, plus a packaging guide.
  • Dependencies

    • Update baseline-browser-mapping to ^2.9.8.

Written for commit 805f844. Summary will update automatically on new commits.

- Implement cut operation (Ctrl+X) for selected patterns
- Add undo capabilities (Ctrl+Z)
- Introduce useContributionHistory hook for state management
- Add a Windows batch script to start the dev environment and log the changes
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 6 files

Prompt for AI agents (all 2 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/components/ContributionCalendar.tsx">

<violation number="1" location="frontend/src/components/ContributionCalendar.tsx:865">
P2: Hardcoded Chinese string breaks internationalization. Use the `t()` function with a translation key instead, like other messages in this file (e.g., `t(&#39;messages.noColoredCells&#39;)`)</violation>

<violation number="2" location="frontend/src/components/ContributionCalendar.tsx:882">
P2: Hardcoded Chinese string breaks internationalization. Use the `t()` function with a translation key and interpolation instead, similar to other messages like `t(&#39;messages.exportSuccess&#39;, { filePath: result.filePath })`.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

- add the build_release.bat packaging script and packaging guide doc
- simplify the application build process on the windows platform
…tions

- removed hard-coded chinese tooltips and used corresponding fields from the translation file
@foxmaybeOI1761640545 foxmaybeOI1761640545 changed the title Feat/add cut and undo feat/add cut and undo Dec 17, 2025
@foxmaybeOI1761640545 foxmaybeOI1761640545 changed the title feat/add cut and undo feat: add cut and undo Dec 17, 2025
Copy link
Owner

@zmrlft zmrlft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

兄弟看一下,写得不错,就是有几个问题得问一下你~

"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.0.1",
"autoprefixer": "^10.4.21",
"baseline-browser-mapping": "^2.9.8",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

欸这个库你有用到吗?


export function useContributionHistory(initialMap: Map<string, number>) {
const [userContributions, setUserContributions] = useState<Map<string, number>>(initialMap);
const [historyLength, setHistoryLength] = useState(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

historyLength 和 futureLength是不是可以去掉,感觉没有用到额,放在这里反而会导致不必要的重渲染

@zmrlft zmrlft mentioned this pull request Jan 26, 2026
@zmrlft zmrlft closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants