TextSegmentCollection - unexpected behaviour when replacing text
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia in ICSharpCode.AvalonEdit/Document/TextSegmentCollection.cs, in ReplaceText, soprattutto nelle righe collegate, e rivedi il comportamento di TextSegment.OnSegmentChanged descritto nella discussione #327. Riproduci l’incoerenza della raccolta TextMarker durante la sostituzione. Il lavoro è completato quando i callback non osservano più il segmento in uno stato intermedio della raccolta e il comportamento di sostituzione esistente rimane intatto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 2.1k
- Fork
- 496
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di icsharpcode/AvalonEdit
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
icsharpcode/AvalonEdit#454 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
icsharpcode/AvalonEdit#449 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
icsharpcode/AvalonEdit#446 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
icsharpcode/AvalonEdit#445 · 1 commento ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = trueForse già presa @JyslaFancy l’ha presa 162 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
icsharpcode/AvalonEdit#444 ·
Tutte le issue di icsharpcode/AvalonEdit
Issue simili
-
type:task ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
elsa-workflows/elsa-foundation#5253 ·
I maintainer di solito rispondono entro 1 giorno