Feature suggestions and discussion [READ THE FIRST POST]
.
How about a change like
--- a/lib/philomena/versions.ex
+++ b/lib/philomena/versions.ex
@@ -48,7 +48,16 @@ defmodule Philomena.Versions do
end
defp difference(previous, nil), do: [eq: previous]
- defp difference(previous, next), do: String.myers_difference(previous, next)
+ defp difference(previous, next) do
+ List.myers_difference(String.split(previous), String.split(next))
+ |> Enum.map(fn {key, value} ->
+ adjust_whitespace({key, Enum.reduce(value, "", fn new, old ->
+ old <> " " <> new
+ end)})
+ end)
+ end
+ defp adjust_whitespace({:eq, str}), do: {:eq, " " <> str <> " "}
+ defp adjust_whitespace({op, str}), do: {op, String.trim(str)}
@doc """
Creates a version.
to turn gibberish like
into something readable
It’s certainly possible to pretty up the code a bit, but the comment history looks way nicer that way.
Background Pony #2A5F
.
@byte[]
Or how about this:
Or how about this:
--- a/lib/philomena/versions.ex
+++ b/lib/philomena/versions.ex
@@ -48,7 +48,14 @@ defmodule Philomena.Versions do
end
defp difference(previous, nil), do: [eq: previous]
- defp difference(previous, next), do: String.myers_difference(previous, next)
+ defp difference(previous, next) do
+ List.myers_difference(split_with_whitespace(previous), split_with_whitespace(next))
+ |> Enum.map(
+ fn {key, value} ->
+ {key, List.foldl(value, "", fn x, acc -> acc <> x end)}
+ end)
+ end
+ defp split_with_whitespace(str), do: String.split(str, ~r{\s+}, include_captures: true)
@doc """
Creates a version.
This properly preserves newlines and such. I don’t think it matters when lines without changes are also included. Most posts don’t contain several pages worth of text and having context is indeed a good thing.
Background Pony #965A
@Background Pony #2A5F
Imo, git includes 3 lines of context because of traditional 80~140 symbols line limit, while natural plain texts may have lines of any size (aka paragraphs). So context from the changed paragraph alone usually should be enough.
Imo, git includes 3 lines of context because of traditional 80~140 symbols line limit, while natural plain texts may have lines of any size (aka paragraphs). So context from the changed paragraph alone usually should be enough.
Background Pony #0F89
@., @byte[], @Background Pony #2A5F
While we’re talking about this, the edit history page ought to also let you see the state of the post (or at least its code) at each state, without the diffs inserted, for easier readability - I have this inelegantly implemented in a userstyle that hides added text and unstyles removed text when I hover the block…
While we’re talking about this, the edit history page ought to also let you see the state of the post (or at least its code) at each state, without the diffs inserted, for easier readability - I have this inelegantly implemented in a userstyle that hides added text and unstyles removed text when I hover the block…
Background Pony #2A5F
@Luna
Not sure if line-wise diffs are optimal for this. Lines of regular text are longer than lines of code. Typically, a paragraph will be one line.
Not sure if line-wise diffs are optimal for this. Lines of regular text are longer than lines of code. Typically, a paragraph will be one line.
Luna
Luna Best Pony~
@Background Pony #2A5F
They will also highlight differences in precise words. This diff is meant to be such that in extremely large posts or pages, where only 1 word changes, it’s possible to display just the snippet that changed with some context around it.
They will also highlight differences in precise words. This diff is meant to be such that in extremely large posts or pages, where only 1 word changes, it’s possible to display just the snippet that changed with some context around it.
Interested in advertising on Derpibooru? Click here for information!
Help fund the $15 daily operational cost of Derpibooru - support us financially!