Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/edeet/priv/static/edeet.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function handle_message(event) {
$('#people data[connection-id="' + message.lost + '"]').fadeOut()
}


if (message.init) {
window.location.hash = message.doc_id;
}
Expand Down
66 changes: 66 additions & 0 deletions apps/edeet/src/edeet_diff.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
%%%-------------------------------------------------------------------
%%% @doc For more info look at https://neil.fraser.name/writing/diff/
%%%
%%% @end
%%%-------------------------------------------------------------------
-module(edeet_diff).

%% API
-export([
diff/2
]).

-type diff_step() :: {add | del, binary()}.


-define(TERNARY(Cond, TrueVal, FalseVal), (case (Cond) of true -> (TrueVal); false -> (FalseVal) end)).

-spec diff(binary(), binary()) -> list(diff_step()).
diff(Bin, Bin) ->
[];

diff(<<>>, Bin) ->
[{ins, Bin}];

diff(Bin, <<>>) ->
[{del, Bin}];

diff(BinA, BinB) ->
tdiff:diff_binaries(BinA, BinB).

%%diff(BinA, BinB) ->
%% Prefix = binary:longest_common_prefix([BinA, BinB]),
%% Suffix = binary:longest_common_suffix([BinA, BinB]),
%%
%% BinA2 = binary:part(BinA, {0, Prefix}),
%% BinA3 = binary:part(BinA2, {Suffix, bit_size(BinA)}),
%%
%% BinB2 = binary:part(BinB, {0, Prefix}),
%% BinB3 = binary:part(BinB2, {Suffix, bit_size(BinB)}),
%%
%% case {BinA3, BinB3} of
%% {<<>>, BinB3} ->
%% [{add, BinB3, Prefix}];
%% {BinA3, <<>>} ->
%% [{del, BinA3, Prefix}];
%% _ ->
%% {Long, Short} = ?TERNARY(bit_size(BinA3) > bit_size(BinB3), {BinA3, BinB3}, {BinB3, BinA3}),
%% case binary:match(Long, Short) of
%% nomatch ->
%% [];
%% {Start, Len} ->
%% Insert = binary:part(Long, {0, Start}),
%% Delete = binary:part(Long, {Len, bit_size(Long)}),
%%
%% [{add, Insert, Start},
%% {del, Delete, Len}]
%%
%% end
%% end.







3 changes: 3 additions & 0 deletions apps/edeet/src/edeet_document.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ get_document(DocId) ->
end.

edit_document(DocId, Bin) ->
[{DocId, _, DocBin}] = ets:lookup(edeet_documents, DocId),
io:format("Diffing: ~p~n", [edeet_diff:diff(DocBin, Bin)]),

ets:update_element(edeet_documents, DocId, {3, Bin}).

-spec generate_doc_id(binary()) -> binary().
Expand Down
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{deps, [
{cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.0.0-pre.8"}}},
{tdiff, ".*", {git, "https://github.com/tomas-abrahamsson/tdiff.git", {tag, "0.1"}}},
{jsone, "1.4.3"},
{lager, "3.4.2"}
]}.
Expand Down
6 changes: 5 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
{<<"ranch">>,
{git,"https://github.com/ninenines/ranch",
{ref,"40809cd2b257a8a53bcb5588ecaa88cc5381ff5c"}},
1}]}.
1},
{<<"tdiff">>,
{git,"https://github.com/tomas-abrahamsson/tdiff.git",
{ref,"bbb54ce20df388f2c7d01e8df30ef471ca98d0fb"}},
0}]}.
[
{pkg_hash,[
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
Expand Down