Skip to content

Conversation

@zichen0116
Copy link
Contributor

@zichen0116 zichen0116 commented Nov 19, 2025

Summary / 概要

This PR adds canvas region copy & paste support for GreenWall, as requested in Issue #48.

本 PR 为 GreenWall 的贡献画布增加了区域复制 / 粘贴功能,对应需求见 Issue #48


What I changed / 具体改动

  1. Selection & copy

    • 支持在贡献画布上选择一个矩形区域(例如通过鼠标拖拽进行框选)。
    • 按下 Ctrl+C(macOS 为 Cmd+C)会将当前选中的区域复制到内部缓冲区。
  2. Paste

    • 按下 Ctrl+V / Cmd+V/鼠标左键 会在当前目标位置粘贴刚刚复制的区域图案。
    • 支持多次粘贴,同一次复制可以在不同位置重复使用。
    • 右键取消图案预览
  3. UI & state

    • 为选中的区域增加了高亮显示,方便用户确认要复制的内容。
    • 在前端状态中保存复制的区域数据,这样画布刷新或多次粘贴时都能复用。

How to use / 使用方式

  1. 选择复制模式;
  2. 过鼠标拖拽选择一块矩形区域,按 Ctrl+C(macOS 为 Cmd+C)复制选中区域;
  3. 将鼠标移动到目标位置(或按照你实现的方式定位目标位置),按 Ctrl+V / Cmd+V/鼠标左键 粘贴;
  4. 可以多次粘贴复制得到的图案,用于快速复用喜欢的形状或文字。

If there is any feedback on interaction details or shortcuts, I'm happy to adjust this implementation. 🙌

如果在交互细节或快捷键上有任何建议,我也可以根据反馈继续调整实现。🙌


Summary by cubic

Adds region copy and paste to the contribution calendar so you can reuse patterns quickly. Implements the workflow requested in Issue #48.

  • New Features

    • Copy Mode toggle in CalendarControls.
    • Drag to select a rectangle; selection is outlined.
    • Ctrl/Cmd+C copies non-empty cells to a buffer; live paste preview follows the cursor.
    • Left-click or Ctrl/Cmd+V pastes; right-click cancels preview. Multiple pastes supported; future dates are skipped.
    • Updated i18n strings and README_zh with usage notes.
  • Bug Fixes

    • Fixed conflicts between paste preview and character preview.

Written for commit b3a962d. Summary will update automatically on new commits.

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 7 files

Prompt for AI agents (all 2 issues)

Understand the root cause of the following 2 issues and fix them.


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

<violation number="1" location="frontend/src/components/ContributionCalendar.tsx:814">
Copy shortcut handling only checks Ctrl+C, so the advertised Cmd+C path on macOS never fires and users cannot copy via the keyboard.</violation>

<violation number="2" location="frontend/src/components/ContributionCalendar.tsx:828">
Paste shortcut handling ignores Cmd+V (metaKey), so macOS users cannot paste via the keyboard despite the feature description promising that shortcut.</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

zichen0116 and others added 2 commits November 19, 2025 13:48
add Cmd+C

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
add Cmd+V

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@zmrlft
Copy link
Owner

zmrlft commented Nov 19, 2025

hi兄弟非常感谢你的贡献!我周末再看看

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.

https://github.com/user-attachments/assets/fcbf04ef-f00b-425b-98d0-50f236dfc066
hi兄弟,感谢你的贡献,发现了两个问题,看看能不能解决:

  • 粘贴的时候会覆盖掉之前复制的内容
  • 和预设字符功能产生了冲突,当我选择一个预设字符的时候,我再也无法右键取消字符预览,左键应用字符了

@zichen0116
Copy link
Contributor Author

hi,很抱歉之前我没有测验清楚就匆忙pr了,我这边已经根据你提到的两个问题做了修复。

@zichen0116 zichen0116 requested a review from zmrlft November 23, 2025 02:58
const coord = getDateCoord(dateStr);
const current =
userContributions.get(dateStr) ??
filteredContributions.find((x) => x.date === dateStr)?.count ??
Copy link
Owner

Choose a reason for hiding this comment

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

被你这么一写,我发现之前设计的这个filteredContributions数据结构有点不合理,因为纵观整页代码,出现了很多次filteredContributions.find()的操作,数组find的时间复杂度是O(n)你这里外层还有一个for(const dateStr of set)那么时间复杂度会来到O(n * m)虽然对现代计算机来说,不会使复制操作卡顿,但是这里确实是可以优化一下~比如把filteredContributions转化成map。这样用map来查询时间复杂度会降为O(1)总的会来到O(n + m)
你的代码我先合并了,这个问题我是看到你这么写突然想到的,你不用改,感谢你的贡献!

Copy link
Owner

Choose a reason for hiding this comment

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

欸也不对,这里还是得保留filteredContributions这个数组结构,因为组件里很多地方(渲染、统计)都需要 filteredContributions,所以原数组仍要保留,不能直接替换。在此基础上再派生一个 Map就差不多。

@zmrlft zmrlft merged commit d8fe1ae into zmrlft:main Dec 6, 2025
4 checks passed
@zichen0116 zichen0116 deleted the feat/canvas-copy-paste branch December 6, 2025 11:04
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.

2 participants