From c05fc92b45ccc1e76420095cf9117c24aa12904f Mon Sep 17 00:00:00 2001 From: Hakan Nilsson Date: Tue, 9 Jan 2024 15:43:55 +0100 Subject: [PATCH] Multiple edits could cause invalid text edits 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. --- apps/els_core/src/els_text.erl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/els_core/src/els_text.erl b/apps/els_core/src/els_text.erl index f4a8dedf1..d21c9d5fd 100644 --- a/apps/els_core/src/els_text.erl +++ b/apps/els_core/src/els_text.erl @@ -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 ->