TextSegmentCollection - unexpected behaviour when replacing text
还没有人认领这个 Issue。
评估
调研方向
从 ICSharpCode.AvalonEdit/Document/TextSegmentCollection.cs 中的 ReplaceText 开始,尤其检查链接的行,并审查 discussion #327 中描述的 TextSegment.OnSegmentChanged 行为。重现替换期间 TextMarker 集合的不一致。完成标准是:回调不再观察到处于集合中间状态的 segment,并且现有的替换行为保持不变。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C#
- 星标
- 2.1k
- 派生
- 496
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
icsharpcode/AvalonEdit 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 76/100
icsharpcode/AvalonEdit#454 ·
-
难度 4/5 3-5 天 新手友好度 48/100
icsharpcode/AvalonEdit#449 ·
-
难度 2/5 1-3 小时 新手友好度 48/100
icsharpcode/AvalonEdit#446 ·
-
难度 4/5 3-5 天 新手友好度 28/100
icsharpcode/AvalonEdit#445 · 1 条评论 ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = true可能已有人在做 @JyslaFancy 于 162 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
icsharpcode/AvalonEdit#444 ·
查看 icsharpcode/AvalonEdit 的全部 Issue
相似的 Issue
-
type:task ux
难度 2/5 1-3 小时 新手友好度 72/100
elsa-workflows/elsa-foundation#5253 ·
维护者通常 1 天内回复