mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-15 06:40:17 +00:00
assistant panel: Fix copying code when trailing newline is missing (#18067)
Follow-up to #17853. Apparently tree-sitter-md extends the range of the content node to include the backticks when there is no newline. Release Notes: - N/A Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
parent
1723713dc2
commit
23e1faa485
1 changed files with 10 additions and 1 deletions
|
@ -3110,6 +3110,8 @@ impl ContextEditor {
|
|||
context_editor_view: &View<ContextEditor>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Option<(String, bool)> {
|
||||
const CODE_FENCE_DELIMITER: &'static str = "```";
|
||||
|
||||
let context_editor = context_editor_view.read(cx).editor.read(cx);
|
||||
|
||||
if context_editor.selections.newest::<Point>(cx).is_empty() {
|
||||
|
@ -3120,10 +3122,17 @@ impl ContextEditor {
|
|||
let offset = snapshot.point_to_offset(head);
|
||||
|
||||
let surrounding_code_block_range = find_surrounding_code_block(snapshot, offset)?;
|
||||
let text = snapshot
|
||||
let mut text = snapshot
|
||||
.text_for_range(surrounding_code_block_range)
|
||||
.collect::<String>();
|
||||
|
||||
// If there is no newline trailing the closing three-backticks, then
|
||||
// tree-sitter-md extends the range of the content node to include
|
||||
// the backticks.
|
||||
if text.ends_with(CODE_FENCE_DELIMITER) {
|
||||
text.drain((text.len() - CODE_FENCE_DELIMITER.len())..);
|
||||
}
|
||||
|
||||
(!text.is_empty()).then_some((text, true))
|
||||
} else {
|
||||
let anchor = context_editor.selections.newest_anchor();
|
||||
|
|
Loading…
Reference in a new issue