Markup mode: `colorify` does not detect existing `{color}(...)` wrapper when switching colors

Đang mở Phù hợp với người mới
#1,129 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu bằng cách đọc packages/editor/src/bundle/toolbar/markup/MToolbarColors.tsx và phần triển khai liên quan của các lệnh markup, sau đó xem lại trường hợp M3 trong packages/editor/src/markup/commands/marks.test.ts. Cập nhật assertion của M3 để bao phủ việc thay thế một wrapper màu hiện có mà không lồng nhau và chạy các bài kiểm tra tập trung cho lệnh markup. Xác minh tương tác trong Storybook: {blue}(text) thay đổi thành {red}(text), còn khi nhấp vào cùng một màu thì wrapper sẽ bị xóa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

In PR #840 the markup-mode colorify was switched from inlineWrapTo to toggleInlineMarkupFactory({before: '{${color}}(', after: ')'}) so that clicking the same color twice unwraps it.

The current implementation of toggleInlineMarkupFactory only detects an exact prefix/suffix match. That breaks color switching:

  • doc: {blue}(text), cursor inside text
  • click Red → expected: {red}(text)
  • actual: nested wrapping like {red}({blue}(text)){red} (because {red}( is not present at the boundaries, so the helper falls through to the wrap branch).

The author marked this with a // TODO: @makhnatkin check markup mode in packages/editor/src/bundle/toolbar/markup/MToolbarColors.tsx.

A pinning test exists in packages/editor/src/markup/commands/marks.test.ts (case M3) that captures the current broken output, so a future fix will flip the assertion.

Suggested approaches

  1. Pre-strip any existing {<word>}(...) wrapper around the selection before applying colorify. A small parser (regex ^\{[a-z0-9-]+\}\( matching the prefix and \)$ for the suffix) is sufficient.
  2. Replace toggleInlineMarkupFactory for color with a dedicated command that recognises the family of {*}( prefixes and either re-wraps with the new color or unwraps when the same color is clicked.
  3. Reach back to inlineWrapTo (no toggle), accepting that markup-mode color clicks always wrap. This loses the toggle-off UX but avoids the nested-wrapper bug.

Out of scope for #840

Fixing this requires command-level rework in markup mode and is independent from the wysiwyg toggle fix. PR #840 ships with the pinning test M3 documenting the known limitation; this issue tracks the follow-up.

Acceptance

  • M3 in packages/editor/src/markup/commands/marks.test.ts flips to assert the correct unwrapped/replaced result.
  • Storybook smoke: in markup mode, {blue}(text) → click Red → {red}(text) (no nesting).
Ngôn ngữ chính
TypeScript
Star
428
Fork
48
Merge trung bình
5 ngày 15 giờ
Pull request đã merge (30 ngày)
47

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của gravity-ui/markdown-editor

Tất cả issue của gravity-ui/markdown-editor

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.