1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-22 11:33:34 +03:00

Show insertion/deletion places in diffs

This commit is contained in:
Artyom 2017-06-10 21:06:38 +02:00
parent 1c5512cd68
commit 0a48a8e2be
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710
3 changed files with 15 additions and 7 deletions

View File

@ -65,8 +65,9 @@ diffR = concatMap hunkToChunk . toList
hunkToChunk (v, PV.Inserted) = [Added (tconcat v)]
hunkToChunk (v, PV.Replaced) = [Added (tconcat v)]
hunkToChunk (v, PV.Unchanged) = map Plain (toList v)
hunkToChunk (_, PV.Deleted) = [] -- because it's not present
-- in the right part
-- it's useful to report deleted things as well because then we can mark
-- them with tiny rectangles like “insert here”
hunkToChunk (_, PV.Deleted) = [Added ""]
-- | Create a diff for the left (original) part. We only want to highlight
-- parts which were deleted or replaced.
@ -83,8 +84,7 @@ diffL = concatMap hunkToChunk
hunkToChunk (v, PV.Inserted) = [Deleted (tconcat v)]
hunkToChunk (v, PV.Replaced) = [Deleted (tconcat v)]
hunkToChunk (v, PV.Unchanged) = map Plain (toList v)
hunkToChunk (_, PV.Deleted) = [] -- because it's not present
-- in the left part
hunkToChunk (_, PV.Deleted) = [Deleted ""]
-- | In a bunch of chunks, find only the part that was changed
trimDiff

View File

@ -512,9 +512,11 @@ renderDiff old new =
mapM_ renderChunk diffRight
toHtml (mconcat (take 10 diffContextBelow)) >> " [...]"
--
renderChunk (Diff.Added x) = ins_ (toHtml (showNewlines x))
renderChunk (Diff.Deleted x) = del_ (toHtml (showNewlines x))
renderChunk (Diff.Plain x) = toHtml x
renderChunk (Diff.Added "") = ins_ [class_ "empty-chunk"] ""
renderChunk (Diff.Added x) = ins_ (toHtml (showNewlines x))
renderChunk (Diff.Deleted "") = del_ [class_ "empty-chunk"] ""
renderChunk (Diff.Deleted x) = del_ (toHtml (showNewlines x))
renderChunk (Diff.Plain x) = toHtml x
--
showNewlines x =
let

View File

@ -77,6 +77,12 @@ textarea:focus {
white-space: pre-wrap;
}
#edits .empty-chunk {
padding-right: 5px;
border: 1px dashed black;
border-radius: 4px;
}
#stats table {
border-collapse: collapse;
border-spacing: 0;