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

オープン 初心者向け
#1,129 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
react, typescript
領域
frontend

調査の方向性

まず packages/editor/src/bundle/toolbar/markup/MToolbarColors.tsx と関連するマークアップコマンドの実装を読み、次に packages/editor/src/markup/commands/marks.test.ts の M3 ケースを確認します。M3 のアサーションを更新して、既存のカラーラッパーをネストせずに置き換えるケースをカバーし、マークアップコマンドの集中テストを実行します。Storybook で操作を確認します。{blue}(text) は {red}(text) に変化し、同じ色をクリックするとラッパーが削除されます。

索引モデルが issue の本文から書いたものです。

説明

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).
主要言語
TypeScript
スター
428
フォーク
48
平均マージ
5日 15時間
マージ済み PR(30日)
47

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

gravity-ui/markdown-editor のほかの issue

gravity-ui/markdown-editor の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。