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

Abierto Apto para principiantes
#1,129 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

Comienza leyendo packages/editor/src/bundle/toolbar/markup/MToolbarColors.tsx y la implementación relacionada de los comandos de markup; después, revisa el caso M3 en packages/editor/src/markup/commands/marks.test.ts. Actualiza la aserción de M3 para cubrir el reemplazo de un wrapper de color existente sin anidamiento y ejecuta las pruebas enfocadas de los comandos de markup. Verifica la interacción en Storybook: {blue}(text) cambia a {red}(text), mientras que al hacer clic en el mismo color se elimina el wrapper.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).
Lenguaje dominante
TypeScript
Estrellas
428
Forks
48
Merge medio
5 d 15 h
PR fusionados (30 d)
47

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de gravity-ui/markdown-editor

Todos los issues de gravity-ui/markdown-editor

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.