Skip to content

Commit

Permalink
Multiple edits could cause invalid text edits (#1478)
Browse files Browse the repository at this point in the history
This is not really a proper fix since it will make text editing
less efficient, but finding the root cause is tricky.

A follow up chagne could be made to fix the root cause.

Fixes #1427.
  • Loading branch information
plux authored Jan 9, 2024
1 parent f0eba6c commit a8390f4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions apps/els_core/src/els_text.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ last_token(Text) ->
apply_edits(Text, []) ->
Text;
apply_edits(Text, Edits) when is_binary(Text) ->
Lines = lists:foldl(
lists:foldl(
fun(Edit, Acc) ->
apply_edit(Acc, 0, Edit)
lines_to_bin(apply_edit(bin_to_lines(Acc), 0, Edit))
end,
bin_to_lines(Text),
Text,
Edits
),
lines_to_bin(Lines).
).

-spec apply_edit(lines(), line_num(), edit()) -> lines().
apply_edit([], L, {#{from := {FromL, _}}, _} = Edit) when L < FromL ->
Expand Down Expand Up @@ -142,9 +141,7 @@ bin_to_lines(Text) ->

-spec ensure_string(binary() | string()) -> string().
ensure_string(Text) when is_binary(Text) ->
els_utils:to_list(Text);
ensure_string(Text) ->
Text.
els_utils:to_list(Text).

-spec strip_comments(binary()) -> binary().
strip_comments(Text) ->
Expand Down

0 comments on commit a8390f4

Please sign in to comment.