Merge branch 'main' into cells
This commit is contained in:
commit
c95aecdd53
59 changed files with 1684 additions and 1362 deletions
|
@ -47,6 +47,7 @@ workspace = { path = "../workspace" }
|
|||
|
||||
aho-corasick = "0.7"
|
||||
anyhow.workspace = true
|
||||
convert_case = "0.6.0"
|
||||
futures.workspace = true
|
||||
indoc = "1.0.4"
|
||||
itertools = "0.10"
|
||||
|
@ -56,12 +57,12 @@ ordered-float.workspace = true
|
|||
parking_lot.workspace = true
|
||||
postage.workspace = true
|
||||
pulldown-cmark = { version = "0.9.2", default-features = false }
|
||||
rand.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
smallvec.workspace = true
|
||||
smol.workspace = true
|
||||
rand.workspace = true
|
||||
|
||||
tree-sitter-rust = { workspace = true, optional = true }
|
||||
tree-sitter-html = { workspace = true, optional = true }
|
||||
|
|
|
@ -28,6 +28,7 @@ use blink_manager::BlinkManager;
|
|||
use client::{ClickhouseEvent, TelemetrySettings};
|
||||
use clock::{Global, ReplicaId};
|
||||
use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
|
||||
use convert_case::{Case, Casing};
|
||||
use copilot::Copilot;
|
||||
pub use display_map::DisplayPoint;
|
||||
use display_map::*;
|
||||
|
@ -89,7 +90,7 @@ use std::{
|
|||
cmp::{self, Ordering, Reverse},
|
||||
mem,
|
||||
num::NonZeroU32,
|
||||
ops::{ControlFlow, Deref, DerefMut, Range},
|
||||
ops::{ControlFlow, Deref, DerefMut, Range, RangeInclusive},
|
||||
path::Path,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
|
@ -231,6 +232,13 @@ actions!(
|
|||
SortLinesCaseInsensitive,
|
||||
ReverseLines,
|
||||
ShuffleLines,
|
||||
ConvertToUpperCase,
|
||||
ConvertToLowerCase,
|
||||
ConvertToTitleCase,
|
||||
ConvertToSnakeCase,
|
||||
ConvertToKebabCase,
|
||||
ConvertToUpperCamelCase,
|
||||
ConvertToLowerCamelCase,
|
||||
Transpose,
|
||||
Cut,
|
||||
Copy,
|
||||
|
@ -353,6 +361,13 @@ pub fn init(cx: &mut AppContext) {
|
|||
cx.add_action(Editor::sort_lines_case_insensitive);
|
||||
cx.add_action(Editor::reverse_lines);
|
||||
cx.add_action(Editor::shuffle_lines);
|
||||
cx.add_action(Editor::convert_to_upper_case);
|
||||
cx.add_action(Editor::convert_to_lower_case);
|
||||
cx.add_action(Editor::convert_to_title_case);
|
||||
cx.add_action(Editor::convert_to_snake_case);
|
||||
cx.add_action(Editor::convert_to_kebab_case);
|
||||
cx.add_action(Editor::convert_to_upper_camel_case);
|
||||
cx.add_action(Editor::convert_to_lower_camel_case);
|
||||
cx.add_action(Editor::delete_to_previous_word_start);
|
||||
cx.add_action(Editor::delete_to_previous_subword_start);
|
||||
cx.add_action(Editor::delete_to_next_word_end);
|
||||
|
@ -4306,6 +4321,97 @@ impl Editor {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn convert_to_upper_case(&mut self, _: &ConvertToUpperCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_uppercase())
|
||||
}
|
||||
|
||||
pub fn convert_to_lower_case(&mut self, _: &ConvertToLowerCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_lowercase())
|
||||
}
|
||||
|
||||
pub fn convert_to_title_case(&mut self, _: &ConvertToTitleCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Title))
|
||||
}
|
||||
|
||||
pub fn convert_to_snake_case(&mut self, _: &ConvertToSnakeCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Snake))
|
||||
}
|
||||
|
||||
pub fn convert_to_kebab_case(&mut self, _: &ConvertToKebabCase, cx: &mut ViewContext<Self>) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Kebab))
|
||||
}
|
||||
|
||||
pub fn convert_to_upper_camel_case(
|
||||
&mut self,
|
||||
_: &ConvertToUpperCamelCase,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::UpperCamel))
|
||||
}
|
||||
|
||||
pub fn convert_to_lower_camel_case(
|
||||
&mut self,
|
||||
_: &ConvertToLowerCamelCase,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.manipulate_text(cx, |text| text.to_case(Case::Camel))
|
||||
}
|
||||
|
||||
fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)
|
||||
where
|
||||
Fn: FnMut(&str) -> String,
|
||||
{
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = self.buffer.read(cx).snapshot(cx);
|
||||
|
||||
let mut new_selections = Vec::new();
|
||||
let mut edits = Vec::new();
|
||||
let mut selection_adjustment = 0i32;
|
||||
|
||||
for selection in self.selections.all::<usize>(cx) {
|
||||
let selection_is_empty = selection.is_empty();
|
||||
|
||||
let (start, end) = if selection_is_empty {
|
||||
let word_range = movement::surrounding_word(
|
||||
&display_map,
|
||||
selection.start.to_display_point(&display_map),
|
||||
);
|
||||
let start = word_range.start.to_offset(&display_map, Bias::Left);
|
||||
let end = word_range.end.to_offset(&display_map, Bias::Left);
|
||||
(start, end)
|
||||
} else {
|
||||
(selection.start, selection.end)
|
||||
};
|
||||
|
||||
let text = buffer.text_for_range(start..end).collect::<String>();
|
||||
let old_length = text.len() as i32;
|
||||
let text = callback(&text);
|
||||
|
||||
new_selections.push(Selection {
|
||||
start: (start as i32 - selection_adjustment) as usize,
|
||||
end: ((start + text.len()) as i32 - selection_adjustment) as usize,
|
||||
goal: SelectionGoal::None,
|
||||
..selection
|
||||
});
|
||||
|
||||
selection_adjustment += old_length - text.len() as i32;
|
||||
|
||||
edits.push((start..end, text));
|
||||
}
|
||||
|
||||
self.transact(cx, |this, cx| {
|
||||
this.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit(edits, None, cx);
|
||||
});
|
||||
|
||||
this.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select(new_selections);
|
||||
});
|
||||
|
||||
this.request_autoscroll(Autoscroll::fit(), cx);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = &display_map.buffer_snapshot;
|
||||
|
@ -7443,6 +7549,78 @@ impl Editor {
|
|||
results
|
||||
}
|
||||
|
||||
pub fn background_highlight_row_ranges<T: 'static>(
|
||||
&self,
|
||||
search_range: Range<Anchor>,
|
||||
display_snapshot: &DisplaySnapshot,
|
||||
count: usize,
|
||||
) -> Vec<RangeInclusive<DisplayPoint>> {
|
||||
let mut results = Vec::new();
|
||||
let buffer = &display_snapshot.buffer_snapshot;
|
||||
let Some((_, ranges)) = self.background_highlights
|
||||
.get(&TypeId::of::<T>()) else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&search_range.start, buffer);
|
||||
if cmp.is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
Ordering::Less
|
||||
}
|
||||
}) {
|
||||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
let mut push_region = |start: Option<Point>, end: Option<Point>| {
|
||||
if let (Some(start_display), Some(end_display)) = (start, end) {
|
||||
results.push(
|
||||
start_display.to_display_point(display_snapshot)
|
||||
..=end_display.to_display_point(display_snapshot),
|
||||
);
|
||||
}
|
||||
};
|
||||
let mut start_row: Option<Point> = None;
|
||||
let mut end_row: Option<Point> = None;
|
||||
if ranges.len() > count {
|
||||
return vec![];
|
||||
}
|
||||
for range in &ranges[start_ix..] {
|
||||
if range.start.cmp(&search_range.end, buffer).is_ge() {
|
||||
break;
|
||||
}
|
||||
let end = range.end.to_point(buffer);
|
||||
if let Some(current_row) = &end_row {
|
||||
if end.row == current_row.row {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let start = range.start.to_point(buffer);
|
||||
|
||||
if start_row.is_none() {
|
||||
assert_eq!(end_row, None);
|
||||
start_row = Some(start);
|
||||
end_row = Some(end);
|
||||
continue;
|
||||
}
|
||||
if let Some(current_end) = end_row.as_mut() {
|
||||
if start.row > current_end.row + 1 {
|
||||
push_region(start_row, end_row);
|
||||
start_row = Some(start);
|
||||
end_row = Some(end);
|
||||
} else {
|
||||
// Merge two hunks.
|
||||
*current_end = end;
|
||||
}
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
// We might still have a hunk that was not rendered (if there was a search hit on the last line)
|
||||
push_region(start_row, end_row);
|
||||
results
|
||||
}
|
||||
|
||||
pub fn highlight_text<T: 'static>(
|
||||
&mut self,
|
||||
ranges: Vec<Range<Anchor>>,
|
||||
|
|
|
@ -525,9 +525,8 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
|
|||
let project = Project::test(fs, [], cx).await;
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project, cx));
|
||||
let workspace = window.root(cx);
|
||||
let window_id = window.window_id();
|
||||
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
|
||||
cx.add_view(window_id, |cx| {
|
||||
window.add_view(cx, |cx| {
|
||||
let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);
|
||||
let mut editor = build_editor(buffer.clone(), cx);
|
||||
let handle = cx.handle();
|
||||
|
@ -1290,7 +1289,8 @@ async fn test_move_start_of_paragraph_end_of_paragraph(cx: &mut gpui::TestAppCon
|
|||
let mut cx = EditorTestContext::new(cx).await;
|
||||
|
||||
let line_height = cx.editor(|editor, cx| editor.style(cx).text.line_height(cx.font_cache()));
|
||||
cx.simulate_window_resize(cx.window_id, vec2f(100., 4. * line_height));
|
||||
let window = cx.window;
|
||||
window.simulate_resize(vec2f(100., 4. * line_height), &mut cx);
|
||||
|
||||
cx.set_state(
|
||||
&r#"ˇone
|
||||
|
@ -1401,7 +1401,8 @@ async fn test_scroll_page_up_page_down(cx: &mut gpui::TestAppContext) {
|
|||
init_test(cx, |_| {});
|
||||
let mut cx = EditorTestContext::new(cx).await;
|
||||
let line_height = cx.editor(|editor, cx| editor.style(cx).text.line_height(cx.font_cache()));
|
||||
cx.simulate_window_resize(cx.window_id, vec2f(1000., 4. * line_height + 0.5));
|
||||
let window = cx.window;
|
||||
window.simulate_resize(vec2f(1000., 4. * line_height + 0.5), &mut cx);
|
||||
|
||||
cx.set_state(
|
||||
&r#"ˇone
|
||||
|
@ -1439,7 +1440,8 @@ async fn test_move_page_up_page_down(cx: &mut gpui::TestAppContext) {
|
|||
let mut cx = EditorTestContext::new(cx).await;
|
||||
|
||||
let line_height = cx.editor(|editor, cx| editor.style(cx).text.line_height(cx.font_cache()));
|
||||
cx.simulate_window_resize(cx.window_id, vec2f(100., 4. * line_height));
|
||||
let window = cx.window;
|
||||
window.simulate_resize(vec2f(100., 4. * line_height), &mut cx);
|
||||
|
||||
cx.set_state(
|
||||
&r#"
|
||||
|
@ -2695,6 +2697,84 @@ async fn test_manipulate_lines_with_multi_selection(cx: &mut TestAppContext) {
|
|||
"});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_manipulate_text(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let mut cx = EditorTestContext::new(cx).await;
|
||||
|
||||
// Test convert_to_upper_case()
|
||||
cx.set_state(indoc! {"
|
||||
«hello worldˇ»
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_upper_case(&ConvertToUpperCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«HELLO WORLDˇ»
|
||||
"});
|
||||
|
||||
// Test convert_to_lower_case()
|
||||
cx.set_state(indoc! {"
|
||||
«HELLO WORLDˇ»
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_lower_case(&ConvertToLowerCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«hello worldˇ»
|
||||
"});
|
||||
|
||||
// From here on out, test more complex cases of manipulate_text()
|
||||
|
||||
// Test no selection case - should affect words cursors are in
|
||||
// Cursor at beginning, middle, and end of word
|
||||
cx.set_state(indoc! {"
|
||||
ˇhello big beauˇtiful worldˇ
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_upper_case(&ConvertToUpperCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«HELLOˇ» big «BEAUTIFULˇ» «WORLDˇ»
|
||||
"});
|
||||
|
||||
// Test multiple selections on a single line and across multiple lines
|
||||
cx.set_state(indoc! {"
|
||||
«Theˇ» quick «brown
|
||||
foxˇ» jumps «overˇ»
|
||||
the «lazyˇ» dog
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_upper_case(&ConvertToUpperCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«THEˇ» quick «BROWN
|
||||
FOXˇ» jumps «OVERˇ»
|
||||
the «LAZYˇ» dog
|
||||
"});
|
||||
|
||||
// Test case where text length grows
|
||||
cx.set_state(indoc! {"
|
||||
«tschüߡ»
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_upper_case(&ConvertToUpperCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«TSCHÜSSˇ»
|
||||
"});
|
||||
|
||||
// Test to make sure we don't crash when text shrinks
|
||||
cx.set_state(indoc! {"
|
||||
aaa_bbbˇ
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_lower_camel_case(&ConvertToLowerCamelCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«aaaBbbˇ»
|
||||
"});
|
||||
|
||||
// Test to make sure we all aware of the fact that each word can grow and shrink
|
||||
// Final selections should be aware of this fact
|
||||
cx.set_state(indoc! {"
|
||||
aaa_bˇbb bbˇb_ccc ˇccc_ddd
|
||||
"});
|
||||
cx.update_editor(|e, cx| e.convert_to_lower_camel_case(&ConvertToLowerCamelCase, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
«aaaBbbˇ» «bbbCccˇ» «cccDddˇ»
|
||||
"});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_duplicate_line(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
|
|
@ -1107,8 +1107,6 @@ impl EditorElement {
|
|||
if layout.is_singleton && scrollbar_settings.selections {
|
||||
let start_anchor = Anchor::min();
|
||||
let end_anchor = Anchor::max();
|
||||
let mut start_row = None;
|
||||
let mut end_row = None;
|
||||
let color = scrollbar_theme.selections;
|
||||
let border = Border {
|
||||
width: 1.,
|
||||
|
@ -1119,54 +1117,32 @@ impl EditorElement {
|
|||
bottom: false,
|
||||
left: true,
|
||||
};
|
||||
let mut push_region = |start, end| {
|
||||
if let (Some(start_display), Some(end_display)) = (start, end) {
|
||||
let start_y = y_for_row(start_display as f32);
|
||||
let mut end_y = y_for_row(end_display as f32);
|
||||
if end_y - start_y < 1. {
|
||||
end_y = start_y + 1.;
|
||||
}
|
||||
let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y));
|
||||
|
||||
scene.push_quad(Quad {
|
||||
bounds,
|
||||
background: Some(color),
|
||||
border,
|
||||
corner_radius: style.thumb.corner_radius,
|
||||
})
|
||||
let mut push_region = |start: DisplayPoint, end: DisplayPoint| {
|
||||
let start_y = y_for_row(start.row() as f32);
|
||||
let mut end_y = y_for_row(end.row() as f32);
|
||||
if end_y - start_y < 1. {
|
||||
end_y = start_y + 1.;
|
||||
}
|
||||
let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y));
|
||||
|
||||
scene.push_quad(Quad {
|
||||
bounds,
|
||||
background: Some(color),
|
||||
border,
|
||||
corner_radius: style.thumb.corner_radius,
|
||||
})
|
||||
};
|
||||
for (row, _) in &editor
|
||||
.background_highlights_in_range_for::<crate::items::BufferSearchHighlights>(
|
||||
let background_ranges = editor
|
||||
.background_highlight_row_ranges::<crate::items::BufferSearchHighlights>(
|
||||
start_anchor..end_anchor,
|
||||
&layout.position_map.snapshot,
|
||||
&theme,
|
||||
)
|
||||
{
|
||||
let start_display = row.start;
|
||||
let end_display = row.end;
|
||||
|
||||
if start_row.is_none() {
|
||||
assert_eq!(end_row, None);
|
||||
start_row = Some(start_display.row());
|
||||
end_row = Some(end_display.row());
|
||||
continue;
|
||||
}
|
||||
if let Some(current_end) = end_row.as_mut() {
|
||||
if start_display.row() > *current_end + 1 {
|
||||
push_region(start_row, end_row);
|
||||
start_row = Some(start_display.row());
|
||||
end_row = Some(end_display.row());
|
||||
} else {
|
||||
// Merge two hunks.
|
||||
*current_end = end_display.row();
|
||||
}
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
50000,
|
||||
);
|
||||
for row in background_ranges {
|
||||
let start = row.start();
|
||||
let end = row.end();
|
||||
push_region(*start, *end);
|
||||
}
|
||||
// We might still have a hunk that was not rendered (if there was a search hit on the last line)
|
||||
push_region(start_row, end_row);
|
||||
}
|
||||
|
||||
if layout.is_singleton && scrollbar_settings.git_diff {
|
||||
|
|
|
@ -99,7 +99,7 @@ impl<'a> EditorLspTestContext<'a> {
|
|||
Self {
|
||||
cx: EditorTestContext {
|
||||
cx,
|
||||
window_id: window.window_id(),
|
||||
window: window.into(),
|
||||
editor,
|
||||
},
|
||||
lsp,
|
||||
|
|
|
@ -3,7 +3,8 @@ use crate::{
|
|||
};
|
||||
use futures::Future;
|
||||
use gpui::{
|
||||
keymap_matcher::Keystroke, AppContext, ContextHandle, ModelContext, ViewContext, ViewHandle,
|
||||
keymap_matcher::Keystroke, AnyWindowHandle, AppContext, ContextHandle, ModelContext,
|
||||
ViewContext, ViewHandle,
|
||||
};
|
||||
use indoc::indoc;
|
||||
use language::{Buffer, BufferSnapshot};
|
||||
|
@ -21,7 +22,7 @@ use super::build_editor;
|
|||
|
||||
pub struct EditorTestContext<'a> {
|
||||
pub cx: &'a mut gpui::TestAppContext,
|
||||
pub window_id: usize,
|
||||
pub window: AnyWindowHandle,
|
||||
pub editor: ViewHandle<Editor>,
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ impl<'a> EditorTestContext<'a> {
|
|||
let editor = window.root(cx);
|
||||
Self {
|
||||
cx,
|
||||
window_id: window.window_id(),
|
||||
window: window.into(),
|
||||
editor,
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +112,8 @@ impl<'a> EditorTestContext<'a> {
|
|||
let keystroke_under_test_handle =
|
||||
self.add_assertion_context(format!("Simulated Keystroke: {:?}", keystroke_text));
|
||||
let keystroke = Keystroke::parse(keystroke_text).unwrap();
|
||||
self.cx.dispatch_keystroke(self.window_id, keystroke, false);
|
||||
|
||||
self.cx.dispatch_keystroke(self.window, keystroke, false);
|
||||
keystroke_under_test_handle
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue