Skip to content

Commit 6050a6c

Browse files
authored
Merge pull request #127 from unisoncomputing/diff-add-remove-line-nums
Diffs: "added" and "removed" line numbers + colors
2 parents b41e431 + f8375b2 commit 6050a6c

File tree

4 files changed

+78
-29
lines changed

4 files changed

+78
-29
lines changed

src/UnisonShare/DefinitionDiffCard.elm

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,28 @@ viewDiffSegment syntaxConfig segment =
7676
]
7777

7878

79+
viewGutter : Int -> Int -> String -> Html msg
80+
viewGutter gutterWidth ln indicator =
81+
span [ class "gutter" ]
82+
[ span [ class "line-number" ]
83+
[ text
84+
(String.padLeft
85+
gutterWidth
86+
' '
87+
(String.fromInt ln)
88+
)
89+
]
90+
, text " "
91+
, span [ class "change-indicator" ] [ text indicator ]
92+
, text " "
93+
]
94+
95+
7996
viewDiffLine : (DiffSegment -> List (Html msg)) -> String -> Int -> DiffLine -> Html msg
8097
viewDiffLine viewSeg changeIndicator gutterWidth line =
8198
let
8299
gutter ln indicator =
83-
span [ class "gutter" ]
84-
[ span [ class "line-number" ]
85-
[ text
86-
(String.padLeft
87-
gutterWidth
88-
' '
89-
(String.fromInt ln)
90-
)
91-
]
92-
, text " "
93-
, span [ class "change-indicator" ] [ text indicator ]
94-
, text " "
95-
]
100+
viewGutter gutterWidth ln indicator
96101
in
97102
case line of
98103
ChangedLine { lineNum, segments } ->

src/UnisonShare/Page/ProjectContributionChangesPage.elm

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,23 +477,43 @@ viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLengt
477477
case ChangeLine.source changeLine of
478478
Just source ->
479479
let
480-
linked =
481-
let
482-
branchRef =
483-
case changeLine of
484-
ChangeLine.Removed _ _ ->
485-
branchDiff.oldBranch.ref
480+
( branchRef, gutterIndicator ) =
481+
case changeLine of
482+
ChangeLine.Removed _ _ ->
483+
( branchDiff.oldBranch.ref, "-" )
486484

487-
_ ->
488-
branchDiff.newBranch.ref
489-
in
485+
ChangeLine.Added _ _ ->
486+
( branchDiff.newBranch.ref, "+" )
487+
488+
_ ->
489+
( branchDiff.newBranch.ref, "" )
490+
491+
linked =
490492
SyntaxConfig.empty
491493
|> SyntaxConfig.withToClick
492494
(Link.projectBranchDefinition projectRef branchRef)
493495

496+
gutter =
497+
let
498+
lns =
499+
List.range 1 (Syntax.numLines source)
500+
501+
viewLn ln =
502+
div [ class "gutter" ]
503+
[ span [ class "line-number" ] [ ln |> String.fromInt |> text ]
504+
, text " "
505+
, span [ class "change-indicator" ] [ text gutterIndicator ]
506+
, text " "
507+
]
508+
in
509+
div [ class "gutter-lines" ] (List.map viewLn lns)
510+
494511
expandedContent =
495-
pre [ class "definition-syntax monochrome" ]
496-
[ code [] [ Syntax.view linked source ] ]
512+
div [ class "definition-source", class (String.toLower (ChangeLine.toString changeLine)) ]
513+
[ gutter
514+
, pre [ class "definition-syntax monochrome" ]
515+
[ code [] [ Syntax.view linked source ] ]
516+
]
497517
in
498518
( Just expandedContent
499519
, Icon.collapseUp

src/css/unison-share/page/project-contribution-changes-page.css

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,33 @@
217217
}
218218
}
219219

220-
& .definition-change.card .definition-syntax {
221-
overflow-x: auto;
222-
padding: 0.5rem 1rem;
220+
.definition-change.card .definition-source {
221+
display: flex;
222+
flex-direction: row;
223+
gap: 0.5rem;
224+
225+
.gutter:last-child {
226+
border-bottom-left-radius: var(--border-radius-base);
227+
}
228+
229+
.definition-syntax {
230+
overflow-x: auto;
231+
line-height: var(--diff-line-height);
232+
}
233+
234+
&.added {
235+
background: var(--color-green-5);
236+
.gutter {
237+
color: var(--color-green-1);
238+
}
239+
}
240+
241+
&.removed {
242+
background: var(--color-pink-5);
243+
.gutter {
244+
color: var(--color-pink-1);
245+
}
246+
}
223247
}
224248

225249
& .definition-change.card .diff-side-by-side {
@@ -323,7 +347,7 @@
323347
line-height: 1;
324348
}
325349

326-
& .definition-change.card .gutter {
350+
& .gutter {
327351
background: var(--u-color_element_subdued);
328352
color: var(--u-color_text_very-subdued);
329353
border-right: 1px solid var(--u-color_border_subdued);

webpack.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const docExamplesReadmeDef = require("./api-stubs/doc-examples-readme-definition
1212
const blogEngineLib = require("./api-stubs/blog-engine-lib.json");
1313
const browseBlog = require("./api-stubs/browse-blog.json");
1414
const notifications = require("./api-stubs/notifications.json");
15-
const branchDiff = require("./api-stubs/branch-diff-with-libs.json");
15+
const branchDiff = require("./api-stubs/branch-diff-weird-equals.json");
1616

1717
// ENV
1818
const API_URL = process.env.API_URL || "http://127.0.0.1:5424";

0 commit comments

Comments
 (0)