@@ -118,8 +118,15 @@ def mark_diffs(
118118 textExp .style .color = Visualization .INSERTED_COLOR
119119 if isinstance (extra2 , m21 .spanner .Spanner ):
120120 insertionPoint = extra2 .getFirst ()
121- insertionPoint .activeSite .insert (insertionPoint .offset , textExp )
121+ if isinstance (insertionPoint , m21 .stream .Measure ):
122+ # insertionPoint is a measure, put the textExp at offset 0
123+ # inside the measure
124+ insertionPoint .insert (0 , textExp )
125+ else :
126+ # insertionPoint is something else, put the textExp right next to it.
127+ insertionPoint .activeSite .insert (insertionPoint .offset , textExp )
122128 else :
129+ # extra2 is not a spanner, put the textExp right next to it
123130 extra2 .activeSite .insert (extra2 .offset , textExp )
124131
125132 elif op [0 ] == "extradel" :
@@ -131,8 +138,15 @@ def mark_diffs(
131138 textExp .style .color = Visualization .DELETED_COLOR
132139 if isinstance (extra1 , m21 .spanner .Spanner ):
133140 insertionPoint = extra1 .getFirst ()
134- insertionPoint .activeSite .insert (insertionPoint .offset , textExp )
141+ if isinstance (insertionPoint , m21 .stream .Measure ):
142+ # insertionPoint is a measure, put the textExp at offset 0
143+ # inside the measure
144+ insertionPoint .insert (0 , textExp )
145+ else :
146+ # insertionPoint is something else, put the textExp right next to it.
147+ insertionPoint .activeSite .insert (insertionPoint .offset , textExp )
135148 else :
149+ # extra1 is not a spanner, put the textExp right next to it
136150 extra1 .activeSite .insert (extra1 .offset , textExp )
137151
138152 elif op [0 ] == "extrasub" :
@@ -155,9 +169,22 @@ def mark_diffs(
155169 if isinstance (extra1 , m21 .spanner .Spanner ):
156170 insertionPoint1 = extra1 .getFirst ()
157171 insertionPoint2 = extra2 .getFirst ()
158- insertionPoint1 .activeSite .insert (insertionPoint1 .offset , textExp1 )
159- insertionPoint2 .activeSite .insert (insertionPoint2 .offset , textExp2 )
172+ if isinstance (insertionPoint1 , m21 .stream .Measure ):
173+ # insertionPoint1 is a measure, put the textExp at offset 0
174+ # inside the measure
175+ insertionPoint1 .insert (0 , textExp )
176+ else :
177+ # insertionPoint1 is something else, put the textExp right next to it.
178+ insertionPoint1 .activeSite .insert (insertionPoint1 .offset , textExp )
179+ if isinstance (insertionPoint2 , m21 .stream .Measure ):
180+ # insertionPoint2 is a measure, put the textExp at offset 0
181+ # inside the measure
182+ insertionPoint2 .insert (0 , textExp )
183+ else :
184+ # insertionPoint2 is something else, put the textExp right next to it.
185+ insertionPoint2 .activeSite .insert (insertionPoint2 .offset , textExp )
160186 else :
187+ # extra is not a spanner, put the textExp right next to it
161188 extra1 .activeSite .insert (extra1 .offset , textExp1 )
162189 extra2 .activeSite .insert (extra2 .offset , textExp2 )
163190
0 commit comments