Skip to content

Commit 8c55fc2

Browse files
committed
Fix inverse diff rendering of segment change and annotation change
1 parent c334dca commit 8c55fc2

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/UnisonShare/DefinitionDiffCard.elm

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ viewTooltip content =
3232
|> Tooltip.withArrow Tooltip.Start
3333

3434

35-
viewDiffSegment : SyntaxConfig msg -> DiffSegment -> List (Html msg)
36-
viewDiffSegment syntaxConfig segment =
35+
type DiffSide
36+
= Left
37+
| Right
38+
39+
40+
viewDiffSegment : DiffSide -> SyntaxConfig msg -> DiffSegment -> List (Html msg)
41+
viewDiffSegment diffSide syntaxConfig segment =
3742
let
3843
viewSegment =
3944
SyntaxSegment.view (SyntaxConfig.withoutDependencyTooltip syntaxConfig)
@@ -49,14 +54,24 @@ viewDiffSegment syntaxConfig segment =
4954
viewSegments_ "diff-segment one-sided" segments
5055

5156
AnnotationChange change ->
57+
let
58+
-- from and to are flipped depending on the side (direction) of the change
59+
( fromHash, toHash ) =
60+
case diffSide of
61+
Left ->
62+
( change.fromHash, change.toHash )
63+
64+
Right ->
65+
( change.toHash, change.fromHash )
66+
in
5267
[ viewTooltip
5368
(div [ class "tooltip-changes-summary" ]
5469
[ div [ class "hash-changed" ]
5570
[ text "The hash changed"
5671
, text " from "
57-
, Hash.view change.fromHash
72+
, Hash.view fromHash
5873
, text " to "
59-
, Hash.view change.toHash
74+
, Hash.view toHash
6075
]
6176
]
6277
)
@@ -67,11 +82,23 @@ viewDiffSegment syntaxConfig segment =
6782
)
6883
]
6984

70-
SegmentChange { from, to } ->
85+
SegmentChange change ->
86+
let
87+
-- from and to are flipped depending on the side (direction) of the change
88+
( from, to ) =
89+
case diffSide of
90+
Left ->
91+
( change.from, change.to )
92+
93+
Right ->
94+
( change.to, change.from )
95+
in
7196
[ viewTooltip
7297
(div [ class "tooltip-changes-summary" ]
7398
[ text "Changed from"
7499
, code [] [ viewSegment from ]
100+
, text "to "
101+
, code [] [ viewSegment to ]
75102
]
76103
)
77104
|> Tooltip.view
@@ -170,16 +197,16 @@ viewDiff cfg { left, right } =
170197
toGutterWidth len =
171198
String.length (String.fromInt len)
172199

173-
toViewDiffSegment isNew =
174-
viewDiffSegment (cfg.toSyntaxConfig isNew)
200+
toViewDiffSegment side =
201+
viewDiffSegment side (cfg.toSyntaxConfig (side == Right))
175202

176203
viewLeftDiffLine =
177-
viewDiffLine (toViewDiffSegment False)
204+
viewDiffLine (toViewDiffSegment Left)
178205
"-"
179206
(toGutterWidth (diffLength left))
180207

181208
viewRightDiffLine =
182-
viewDiffLine (toViewDiffSegment True)
209+
viewDiffLine (toViewDiffSegment Right)
183210
"+"
184211
(toGutterWidth (diffLength right))
185212

0 commit comments

Comments
 (0)