From 8a8e29573f7d8a87ecdce1ee071382cb05e12857 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:27:53 -0600 Subject: [PATCH] fix panics (cherry-pick #13554) (#13557) Cherry-picked fix panics (#13554) Release Notes: - Fixed a panic when editing HTML near the end of a file - Fixed a panic when editing settings.json from inside the .zed directory Co-authored-by: Conrad Irwin --- crates/editor/src/editor.rs | 3 +++ crates/project/src/project.rs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 65835cc79b29f90eaddf88977cf9ec72794ed438..9c0419cbdf21fe02977ac7a1398e2d73083eec2b 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2849,6 +2849,9 @@ impl Editor { let start_offset = TO::to_offset(&range.start, &buffer_snapshot); let end_offset = start_offset + end_difference; let start_offset = start_offset + start_difference; + if start_offset > buffer_snapshot.len() || end_offset > buffer_snapshot.len() { + continue; + } let start = buffer_snapshot.anchor_after(start_offset); let end = buffer_snapshot.anchor_after(end_offset); linked_edits diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 15f86322a79ff0607e51ad6ed061c747da116eb9..011877b02fadc3a1719b330540f54de356d7a86a 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -8193,7 +8193,7 @@ impl Project { } }; - if abs_path.ends_with(local_settings_file_relative_path()) { + if path.ends_with(local_settings_file_relative_path()) { let settings_dir = Arc::from( path.ancestors() .nth(local_settings_file_relative_path().components().count()) @@ -8210,7 +8210,7 @@ impl Project { }, ) }); - } else if abs_path.ends_with(local_tasks_file_relative_path()) { + } else if path.ends_with(local_tasks_file_relative_path()) { self.task_inventory().update(cx, |task_inventory, cx| { if removed { task_inventory.remove_local_static_source(&abs_path); @@ -8230,7 +8230,7 @@ impl Project { ); } }) - } else if abs_path.ends_with(local_vscode_tasks_file_relative_path()) { + } else if path.ends_with(local_vscode_tasks_file_relative_path()) { self.task_inventory().update(cx, |task_inventory, cx| { if removed { task_inventory.remove_local_static_source(&abs_path);