editor: Translate utf16 to utf8 offsets in `copy_highlight_json` (#40981)

Lukas Wirth created

Fixes ZED-2FM

Release Notes:

- Fixed panic in copy highlight json action

Change summary

crates/editor/src/editor.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -21351,7 +21351,10 @@ impl Editor {
                 if selection.range.is_empty() {
                     None
                 } else {
-                    Some(selection.range)
+                    Some(
+                        snapshot.offset_utf16_to_offset(OffsetUtf16(selection.range.start))
+                            ..snapshot.offset_utf16_to_offset(OffsetUtf16(selection.range.end)),
+                    )
                 }
             })
             .unwrap_or_else(|| 0..snapshot.len());