From 0a48a8e2bed966e58fa1f12a635bcc135786768c Mon Sep 17 00:00:00 2001 From: Artyom Date: Sat, 10 Jun 2017 21:06:38 +0200 Subject: [PATCH] Show insertion/deletion places in diffs --- src/Guide/Diff.hs | 8 ++++---- src/Guide/Views.hs | 8 +++++--- static/admin.css | 6 ++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Guide/Diff.hs b/src/Guide/Diff.hs index 6f596d0..ef17440 100644 --- a/src/Guide/Diff.hs +++ b/src/Guide/Diff.hs @@ -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 diff --git a/src/Guide/Views.hs b/src/Guide/Views.hs index e0042ad..c8e5f59 100644 --- a/src/Guide/Views.hs +++ b/src/Guide/Views.hs @@ -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 diff --git a/static/admin.css b/static/admin.css index 68f3b32..297c470 100644 --- a/static/admin.css +++ b/static/admin.css @@ -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;