Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into picker
Marshall Bowersfe28d8faeab7
diff --cc crates/editor2/src/editor.rsindex 4d58335783d,8c691b33509..ea76a7b57d9--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@@ -9054,138 -9057,142 +9057,142 @@@ impl Editortelemetry.report_clickhouse_event(event, telemetry_settings)}- // /// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines,- // /// with each line being an array of {text, highlight} objects.- // fn copy_highlight_json(&mut self, _: &CopyHighlightJson, cx: &mut ViewContext<Self>) {- // let Some(buffer) = self.buffer.read(cx).as_singleton() else {- // return;- // };+ /// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines,+ /// with each line being an array of {text, highlight} objects.+ fn copy_highlight_json(&mut self, _: &CopyHighlightJson, cx: &mut ViewContext<Self>) {+ let Some(buffer) = self.buffer.read(cx).as_singleton() else {+ return;+ };- // #[derive(Serialize)]- // struct Chunk<'a> {- // text: String,- // highlight: Option<&'a str>,- // }+ #[derive(Serialize)]+ struct Chunk<'a> {+ text: String,+ highlight: Option<&'a str>,+ }- // let snapshot = buffer.read(cx).snapshot();- // let range = self- // .selected_text_range(cx)- // .and_then(|selected_range| {- // if selected_range.is_empty() {- // None- // } else {- // Some(selected_range)- // }- // })- // .unwrap_or_else(|| 0..snapshot.len());-- // let chunks = snapshot.chunks(range, true);- // let mut lines = Vec::new();- // let mut line: VecDeque<Chunk> = VecDeque::new();-- // let theme = &theme::current(cx).editor.syntax;-- // for chunk in chunks {- // let highlight = chunk.syntax_highlight_id.and_then(|id| id.name(theme));- // let mut chunk_lines = chunk.text.split("\n").peekable();- // while let Some(text) = chunk_lines.next() {- // let mut merged_with_last_token = false;- // if let Some(last_token) = line.back_mut() {- // if last_token.highlight == highlight {- // last_token.text.push_str(text);- // merged_with_last_token = true;- // }- // }+ let snapshot = buffer.read(cx).snapshot();+ let range = self+ .selected_text_range(cx)+ .and_then(|selected_range| {+ if selected_range.is_empty() {+ None+ } else {+ Some(selected_range)+ }+ })+ .unwrap_or_else(|| 0..snapshot.len());- // if !merged_with_last_token {- // line.push_back(Chunk {- // text: text.into(),- // highlight,- // });- // }+ let chunks = snapshot.chunks(range, true);+ let mut lines = Vec::new();+ let mut line: VecDeque<Chunk> = VecDeque::new();- // if chunk_lines.peek().is_some() {- // if line.len() > 1 && line.front().unwrap().text.is_empty() {- // line.pop_front();- // }- // if line.len() > 1 && line.back().unwrap().text.is_empty() {- // line.pop_back();- // }+ let Some(style) = self.style.as_ref() else {+ return;+ };- // lines.push(mem::take(&mut line));- // }- // }- // }+ for chunk in chunks {+ let highlight = chunk+ .syntax_highlight_id+ .and_then(|id| id.name(&style.syntax));+ let mut chunk_lines = chunk.text.split("\n").peekable();+ while let Some(text) = chunk_lines.next() {+ let mut merged_with_last_token = false;+ if let Some(last_token) = line.back_mut() {+ if last_token.highlight == highlight {+ last_token.text.push_str(text);+ merged_with_last_token = true;+ }+ }- // let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else {- // return;- // };- // cx.write_to_clipboard(ClipboardItem::new(lines));- // }+ if !merged_with_last_token {+ line.push_back(Chunk {+ text: text.into(),+ highlight,+ });+ }- // pub fn inlay_hint_cache(&self) -> &InlayHintCache {- // &self.inlay_hint_cache- // }+ if chunk_lines.peek().is_some() {+ if line.len() > 1 && line.front().unwrap().text.is_empty() {+ line.pop_front();+ }+ if line.len() > 1 && line.back().unwrap().text.is_empty() {+ line.pop_back();+ }- // pub fn replay_insert_event(- // &mut self,- // text: &str,- // relative_utf16_range: Option<Range<isize>>,- // cx: &mut ViewContext<Self>,- // ) {- // if !self.input_enabled {- // cx.emit(Event::InputIgnored { text: text.into() });- // return;- // }- // if let Some(relative_utf16_range) = relative_utf16_range {- // let selections = self.selections.all::<OffsetUtf16>(cx);- // self.change_selections(None, cx, |s| {- // let new_ranges = selections.into_iter().map(|range| {- // let start = OffsetUtf16(- // range- // .head()- // .0- // .saturating_add_signed(relative_utf16_range.start),- // );- // let end = OffsetUtf16(- // range- // .head()- // .0- // .saturating_add_signed(relative_utf16_range.end),- // );- // start..end- // });- // s.select_ranges(new_ranges);- // });- // }+ lines.push(mem::take(&mut line));+ }+ }+ }- // self.handle_input(text, cx);- // }+ let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else {+ return;+ };+ cx.write_to_clipboard(ClipboardItem::new(lines));+ }- // pub fn supports_inlay_hints(&self, cx: &AppContext) -> bool {- // let Some(project) = self.project.as_ref() else {- // return false;- // };- // let project = project.read(cx);-- // let mut supports = false;- // self.buffer().read(cx).for_each_buffer(|buffer| {- // if !supports {- // supports = project- // .language_servers_for_buffer(buffer.read(cx), cx)- // .any(- // |(_, server)| match server.capabilities().inlay_hint_provider {- // Some(lsp::OneOf::Left(enabled)) => enabled,- // Some(lsp::OneOf::Right(_)) => true,- // None => false,- // },- // )- // }- // });- // supports- // }+ pub fn inlay_hint_cache(&self) -> &InlayHintCache {+ &self.inlay_hint_cache+ }++ pub fn replay_insert_event(+ &mut self,+ text: &str,+ relative_utf16_range: Option<Range<isize>>,+ cx: &mut ViewContext<Self>,+ ) {+ if !self.input_enabled {+ cx.emit(Event::InputIgnored { text: text.into() });+ return;+ }+ if let Some(relative_utf16_range) = relative_utf16_range {+ let selections = self.selections.all::<OffsetUtf16>(cx);+ self.change_selections(None, cx, |s| {+ let new_ranges = selections.into_iter().map(|range| {+ let start = OffsetUtf16(+ range+ .head()+ .0+ .saturating_add_signed(relative_utf16_range.start),+ );+ let end = OffsetUtf16(+ range+ .head()+ .0+ .saturating_add_signed(relative_utf16_range.end),+ );+ start..end+ });+ s.select_ranges(new_ranges);+ });+ }++ self.handle_input(text, cx);+ }++ pub fn supports_inlay_hints(&self, cx: &AppContext) -> bool {+ let Some(project) = self.project.as_ref() else {+ return false;+ };+ let project = project.read(cx);++ let mut supports = false;+ self.buffer().read(cx).for_each_buffer(|buffer| {+ if !supports {+ supports = project+ .language_servers_for_buffer(buffer.read(cx), cx)+ .any(+ |(_, server)| match server.capabilities().inlay_hint_provider {+ Some(lsp::OneOf::Left(enabled)) => enabled,+ Some(lsp::OneOf::Right(_)) => true,+ None => false,+ },+ )+ }+ });+ supports+ }- fn focus(&self, cx: &mut WindowContext) {+ pub fn focus(&self, cx: &mut WindowContext) {cx.focus(&self.focus_handle)}}diff --cc crates/editor2/src/element.rsindex cf4f68d23a4,34ce39fd8a3..04b8494a888--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@@ -8,10 -15,12 +15,12 @@@ use crate::use anyhow::Result;use collections::{BTreeMap, HashMap};use gpui::{- black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, BorrowWindow,- Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, Edges, Element, ElementId,- Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, ScrollWheelEvent, ShapedGlyph,- Size, StatefulInteractivity, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,+ black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,+ BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,+ Edges, Element, ElementId, Entity, GlobalElementId, Hsla, KeyDownEvent, KeyListener, KeyMatch,+ Line, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,- ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,- TextSystem, ViewContext, WindowContext,++ ScrollWheelEvent, ShapedGlyph, Size, Style, TextRun, TextStyle, TextSystem, ViewContext,++ WindowContext,};use itertools::Itertools;use language::language_settings::ShowWhitespaceSetting;