Root cause
ISegment.BaselineText is a read-only, computed ITsString property (declared in InterfaceAdditions.cs:542; implemented in OverridesCellar.cs:4397-4400). Its backing store is IStTxtPara.Contents.
The following methods in flexlibs2/code/TextsWords/SegmentOperations.py all follow the same broken pattern:
- Manually add/remove/restructure entries in
para_obj.SegmentsOS (or call SegmentsOS.Clear()).
- Then try to set
segment.BaselineText.set_String(...) or segment.BaselineText.CopyAlternatives(...) on the new/moved segments.
Both steps are wrong. SegmentsOS is owned by AnalysisAdjuster, not caller code. The correct LCM idiom is to edit IStTxtPara.Contents via a TsStrBldr; the ContentsSideEffects notification fires AnalysisAdjuster.AdjustAnalysis which rebuilds and reconciles SegmentsOS automatically.
Entangled sites (file:line)
All in flexlibs2/code/TextsWords/SegmentOperations.py:
| Method |
Line(s) |
Nature of entanglement |
Create |
519 (SegmentsOS.Add) + 523 (set_String) |
Creates segment, manually adds to SegmentsOS, then tries to set BaselineText |
Duplicate |
634 (SegmentsOS.Add) + 638 (CopyAlternatives) |
Adds to SegmentsOS, then calls CopyAlternatives on ITsString (IMultiString method) |
SplitSegment |
890, 897 (SegmentsOS.Insert) + 892, 899 (set_String) |
Inserts two new segments, sets text on each |
MergeSegments |
992 (SegmentsOS.Insert) + 995 (set_String) |
Creates merged segment, inserts into SegmentsOS, sets text |
RebuildSegments |
1340 (SegmentsOS.Clear) + 1363 (SegmentsOS.Add) + 1367 (set_String) |
Clears all segments, creates new ones, sets text on each |
Correct write idiom (from /lex-domain analysis)
para = segment_obj.Paragraph # IStTxtPara
begin = segment_obj.BeginOffset
end = segment_obj.EndOffset
bldr = para.Contents.GetBldr()
new_run = TsStringUtils.MakeString(new_text, ws)
bldr.ReplaceTsString(begin, end, new_run)
para.Contents = bldr.GetString() # ContentsSideEffects -> AnalysisAdjuster.AdjustAnalysis
For Create/Split/Merge/Rebuild the equivalent idiom is to build the full desired Contents string for the paragraph and assign it once; AnalysisAdjuster handles all segment reconciliation.
Relevant liblcm sources
InterfaceAdditions.cs:542 -- ISegment.BaselineText declaration (ITsString, get-only)
OverridesCellar.cs:4397-4400 -- computed implementation returning substring of para Contents
StTxtPara.cs:533-577 -- ContentsSideEffects triggering AnalysisAdjuster.AdjustAnalysis
(Source tree: D:\Github\_Projects\_LEX\liblcm\)
Dependency: test coverage
QC review of commit 295f613 noted there are currently no live tests for Duplicate, SplitSegment, or MergeSegments. These methods must have live-test coverage established before the architectural rewrite can be safely validated. Recommend filing or reusing a test-coverage issue alongside this work.
Context
Spun out of #172 after /lex-domain analysis identified that applying the bldr.ReplaceTsString fix mechanically to these methods would fight AnalysisAdjuster and likely regress. The safe read/write sites from #172 (GetSyncableProperties and SetBaselineText) were fixed directly in #172's commit; the entangled sites are deferred here.
Root cause
ISegment.BaselineTextis a read-only, computedITsStringproperty (declared inInterfaceAdditions.cs:542; implemented inOverridesCellar.cs:4397-4400). Its backing store isIStTxtPara.Contents.The following methods in
flexlibs2/code/TextsWords/SegmentOperations.pyall follow the same broken pattern:para_obj.SegmentsOS(or callSegmentsOS.Clear()).segment.BaselineText.set_String(...)orsegment.BaselineText.CopyAlternatives(...)on the new/moved segments.Both steps are wrong.
SegmentsOSis owned byAnalysisAdjuster, not caller code. The correct LCM idiom is to editIStTxtPara.Contentsvia aTsStrBldr; theContentsSideEffectsnotification firesAnalysisAdjuster.AdjustAnalysiswhich rebuilds and reconcilesSegmentsOSautomatically.Entangled sites (file:line)
All in
flexlibs2/code/TextsWords/SegmentOperations.py:CreateSegmentsOS.Add) + 523 (set_String)DuplicateSegmentsOS.Add) + 638 (CopyAlternatives)SplitSegmentSegmentsOS.Insert) + 892, 899 (set_String)MergeSegmentsSegmentsOS.Insert) + 995 (set_String)RebuildSegmentsSegmentsOS.Clear) + 1363 (SegmentsOS.Add) + 1367 (set_String)Correct write idiom (from /lex-domain analysis)
For Create/Split/Merge/Rebuild the equivalent idiom is to build the full desired
Contentsstring for the paragraph and assign it once; AnalysisAdjuster handles all segment reconciliation.Relevant liblcm sources
InterfaceAdditions.cs:542--ISegment.BaselineTextdeclaration (ITsString, get-only)OverridesCellar.cs:4397-4400-- computed implementation returning substring of para ContentsStTxtPara.cs:533-577--ContentsSideEffectstriggeringAnalysisAdjuster.AdjustAnalysis(Source tree:
D:\Github\_Projects\_LEX\liblcm\)Dependency: test coverage
QC review of commit
295f613noted there are currently no live tests for Duplicate, SplitSegment, or MergeSegments. These methods must have live-test coverage established before the architectural rewrite can be safely validated. Recommend filing or reusing a test-coverage issue alongside this work.Context
Spun out of #172 after
/lex-domainanalysis identified that applying thebldr.ReplaceTsStringfix mechanically to these methods would fightAnalysisAdjusterand likely regress. The safe read/write sites from #172 (GetSyncablePropertiesandSetBaselineText) were fixed directly in #172's commit; the entangled sites are deferred here.