TextSegmentCollection - unexpected behaviour when replacing text
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza en ICSharpCode.AvalonEdit/Document/TextSegmentCollection.cs, en ReplaceText, especialmente en las líneas vinculadas, y revisa el comportamiento de TextSegment.OnSegmentChanged descrito en la discusión #327. Reproduce la inconsistencia de la colección TextMarker durante el reemplazo. Se considera terminado cuando los callbacks ya no observan el segmento en un estado intermedio de la colección y el comportamiento de reemplazo existente permanece intacto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I've come across an issue which I suspect is caused by the internal implementation of TextSegmentCollection.ReplaceText, specifically this section
A segment gets removed from the collection, then manipulated, then re-added to the collection.
If there is any logic reacting to the in-between manipulation, it may behave unexpectedly, since the segment is not a member of the collection (at that time).
My problem were Segments (specifically TextMarkers) which got replaced in their entirety, but would claim not to be members of their corresponding collection during a TextSegment.OnSegmentChanged invocation, only to "magically" reappear during later calls (specifically redraws). See https://github.com/icsharpcode/AvalonEdit/discussions/327
There may be some hacky ways to work around the problem (sadly there are no "added/removed" triggers for the segment collection.. and it's sealed...). One could post some handler via Dispatcher to "recheck" a segment... but that's... messy.
A clean solution to my mind would be adding BeginChange() / EndChange() methods to TextSegment (similar to what exists for TextDocument) which suppress all OnSegmentChanged invocations and rework the ReplaceText method to use those methods:
...
segment.BeginChange();
RemoveSegment(segment);
segment.StartOffset = offset + change.RemovalLength;
segment.Length = Math.Max(0, remainingLength);
AddSegment(segment);
segment.EndChange();
...
That would defer any OnSegmentChanged invocation until the segment is once again in an expected state.
- Lenguaje dominante
- C#
- Estrellas
- 2.1k
- Forks
- 496
- Métricas de merge de PR
- Sin PR fusionados en 30 d
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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de icsharpcode/AvalonEdit
-
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
icsharpcode/AvalonEdit#454 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
icsharpcode/AvalonEdit#449 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
icsharpcode/AvalonEdit#446 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
icsharpcode/AvalonEdit#445 · 1 comentario ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = truePosiblemente ocupada @JyslaFancy la tomó hace 162 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
icsharpcode/AvalonEdit#444 ·
Todos los issues de icsharpcode/AvalonEdit
Issues similares
-
type:task ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
elsa-workflows/elsa-foundation#5253 ·
Los mantenedores suelen responder en 1 día