|
|
|
@ -5,6 +5,7 @@ pub mod movement;
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod test;
|
|
|
|
|
|
|
|
|
|
use buffer::rope::TextDimension;
|
|
|
|
|
use clock::ReplicaId;
|
|
|
|
|
pub use display_map::DisplayPoint;
|
|
|
|
|
use display_map::*;
|
|
|
|
@ -512,7 +513,7 @@ impl Editor {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut selections = self.point_selections(cx).peekable();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).peekable();
|
|
|
|
|
let first_cursor_top = selections
|
|
|
|
|
.peek()
|
|
|
|
|
.unwrap()
|
|
|
|
@ -564,7 +565,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) -> bool {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let selections = self.point_selections(cx);
|
|
|
|
|
let selections = self.selections::<Point>(cx);
|
|
|
|
|
let mut target_left = std::f32::INFINITY;
|
|
|
|
|
let mut target_right = 0.0_f32;
|
|
|
|
|
for selection in selections {
|
|
|
|
@ -655,7 +656,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
fn end_selection(&mut self, cx: &mut ViewContext<Self>) {
|
|
|
|
|
if let Some(selection) = self.pending_selection.take() {
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let ix = self.selection_insertion_index(&selections, selection.start);
|
|
|
|
|
selections.insert(ix, selection);
|
|
|
|
|
self.update_selections(selections, false, cx);
|
|
|
|
@ -668,12 +669,12 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
|
|
|
|
|
if let Some(pending_selection) = self.pending_selection.take() {
|
|
|
|
|
if self.point_selections(cx).next().is_none() {
|
|
|
|
|
if self.selections::<Point>(cx).next().is_none() {
|
|
|
|
|
self.update_selections(vec![pending_selection], true, cx);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let selection_count = self.selection_count(cx);
|
|
|
|
|
let selections = self.point_selections(cx);
|
|
|
|
|
let selections = self.selections::<Point>(cx);
|
|
|
|
|
let mut oldest_selection = selections.min_by_key(|s| s.id).unwrap().clone();
|
|
|
|
|
if selection_count == 1 {
|
|
|
|
|
oldest_selection.start = oldest_selection.head().clone();
|
|
|
|
@ -760,7 +761,7 @@ impl Editor {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let mut old_selections = SmallVec::<[_; 32]>::new();
|
|
|
|
|
{
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
for selection in selections.iter() {
|
|
|
|
|
let start_point = selection.start;
|
|
|
|
@ -882,7 +883,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let old_selections = self.offset_selections(cx).collect::<SmallVec<[_; 32]>>();
|
|
|
|
|
let old_selections = self.selections::<usize>(cx).collect::<SmallVec<[_; 32]>>();
|
|
|
|
|
let mut new_selections = Vec::new();
|
|
|
|
|
self.buffer.update(cx, |buffer, cx| {
|
|
|
|
|
let edit_ranges = old_selections.iter().map(|s| s.start..s.end);
|
|
|
|
@ -913,7 +914,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn autoclose_pairs(&mut self, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let selections = self.offset_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
|
|
|
|
let new_autoclose_pair_state = self.buffer.update(cx, |buffer, cx| {
|
|
|
|
|
let autoclose_pair = buffer.language().and_then(|language| {
|
|
|
|
|
let first_selection_start = selections.first().unwrap().start;
|
|
|
|
@ -970,7 +971,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
fn skip_autoclose_end(&mut self, text: &str, cx: &mut ViewContext<Self>) -> bool {
|
|
|
|
|
let old_selection_count = self.selection_count(cx);
|
|
|
|
|
let old_selections = self.offset_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let old_selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
|
|
|
|
let autoclose_pair_state = if let Some(autoclose_pair_state) = self.autoclose_stack.last() {
|
|
|
|
|
autoclose_pair_state
|
|
|
|
|
} else {
|
|
|
|
@ -985,7 +986,7 @@ impl Editor {
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
if old_selections
|
|
|
|
|
.iter()
|
|
|
|
|
.zip(autoclose_pair_state.ranges.offset_ranges(buffer))
|
|
|
|
|
.zip(autoclose_pair_state.ranges.ranges::<usize, _>(buffer))
|
|
|
|
|
.all(|(selection, autoclose_range)| {
|
|
|
|
|
let autoclose_range_end = autoclose_range.end.to_offset(buffer);
|
|
|
|
|
selection.is_empty() && selection.start == autoclose_range_end
|
|
|
|
@ -1021,7 +1022,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn backspace(&mut self, _: &Backspace, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
if selection.is_empty() {
|
|
|
|
@ -1041,7 +1042,7 @@ impl Editor {
|
|
|
|
|
pub fn delete(&mut self, _: &Delete, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
if selection.is_empty() {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1060,7 +1061,7 @@ impl Editor {
|
|
|
|
|
pub fn tab(&mut self, _: &Tab, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let tab_size = self.build_settings.borrow()(cx).tab_size;
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
self.buffer.update(cx, |buffer, cx| {
|
|
|
|
|
let mut last_indented_row = None;
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
@ -1101,7 +1102,7 @@ impl Editor {
|
|
|
|
|
pub fn delete_line(&mut self, _: &DeleteLine, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
@ -1176,7 +1177,7 @@ impl Editor {
|
|
|
|
|
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
@ -1234,7 +1235,7 @@ impl Editor {
|
|
|
|
|
pub fn move_line_up(&mut self, _: &MoveLineUp, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
@ -1324,7 +1325,7 @@ impl Editor {
|
|
|
|
|
pub fn move_line_down(&mut self, _: &MoveLineDown, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
@ -1411,7 +1412,7 @@ impl Editor {
|
|
|
|
|
pub fn cut(&mut self, _: &Cut, cx: &mut ViewContext<Self>) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let mut text = String::new();
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
|
|
|
|
{
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
@ -1442,7 +1443,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn copy(&mut self, _: &Copy, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
let max_point = buffer.max_point();
|
|
|
|
|
let mut text = String::new();
|
|
|
|
@ -1474,7 +1475,7 @@ impl Editor {
|
|
|
|
|
if let Some(item) = cx.as_mut().read_from_clipboard() {
|
|
|
|
|
let clipboard_text = item.text();
|
|
|
|
|
if let Some(mut clipboard_selections) = item.metadata::<Vec<ClipboardSelection>>() {
|
|
|
|
|
let mut selections = self.offset_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
|
|
|
|
let all_selections_were_entire_line =
|
|
|
|
|
clipboard_selections.iter().all(|s| s.is_entire_line);
|
|
|
|
|
if clipboard_selections.len() != selections.len() {
|
|
|
|
@ -1537,7 +1538,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn move_left(&mut self, _: &MoveLeft, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let start = selection.start.to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let end = selection.end.to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1559,7 +1560,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_left(&mut self, _: &SelectLeft, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let cursor = movement::left(&display_map, head)
|
|
|
|
@ -1573,7 +1574,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn move_right(&mut self, _: &MoveRight, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let start = selection.start.to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let end = selection.end.to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1595,7 +1596,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_right(&mut self, _: &SelectRight, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let cursor = movement::right(&display_map, head)
|
|
|
|
@ -1614,7 +1615,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let start = selection.start.to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let end = selection.end.to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1634,7 +1635,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_up(&mut self, _: &SelectUp, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let (head, goal) = movement::up(&display_map, head, selection.goal).unwrap();
|
|
|
|
@ -1652,7 +1653,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let start = selection.start.to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let end = selection.end.to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1672,7 +1673,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_down(&mut self, _: &SelectDown, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let (head, goal) = movement::down(&display_map, head, selection.goal).unwrap();
|
|
|
|
@ -1689,7 +1690,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::prev_word_boundary(&display_map, head).unwrap();
|
|
|
|
@ -1708,7 +1709,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::prev_word_boundary(&display_map, head).unwrap();
|
|
|
|
@ -1726,7 +1727,7 @@ impl Editor {
|
|
|
|
|
) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
if selection.is_empty() {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1747,7 +1748,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::next_word_boundary(&display_map, head).unwrap();
|
|
|
|
@ -1766,7 +1767,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::next_word_boundary(&display_map, head).unwrap();
|
|
|
|
@ -1784,7 +1785,7 @@ impl Editor {
|
|
|
|
|
) {
|
|
|
|
|
self.start_transaction(cx);
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
if selection.is_empty() {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1805,7 +1806,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::line_beginning(&display_map, head, true).unwrap();
|
|
|
|
@ -1824,7 +1825,7 @@ impl Editor {
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::line_beginning(&display_map, head, *toggle_indent).unwrap();
|
|
|
|
@ -1847,7 +1848,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn move_to_end_of_line(&mut self, _: &MoveToEndOfLine, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
{
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
@ -1864,7 +1865,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_to_end_of_line(&mut self, _: &SelectToEndOfLine, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
let head = selection.head().to_display_point(&display_map, Bias::Left);
|
|
|
|
|
let new_head = movement::line_end(&display_map, head).unwrap();
|
|
|
|
@ -1900,7 +1901,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn select_to_beginning(&mut self, _: &SelectToBeginning, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let mut selection = self.point_selections(cx).last().unwrap().clone();
|
|
|
|
|
let mut selection = self.selections::<Point>(cx).last().unwrap().clone();
|
|
|
|
|
selection.set_head(Point::zero());
|
|
|
|
|
self.update_selections(vec![selection], true, cx);
|
|
|
|
|
}
|
|
|
|
@ -1919,7 +1920,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn select_to_end(&mut self, _: &SelectToEnd, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let mut selection = self.offset_selections(cx).last().unwrap().clone();
|
|
|
|
|
let mut selection = self.selections::<usize>(cx).last().unwrap().clone();
|
|
|
|
|
selection.set_head(self.buffer.read(cx).len());
|
|
|
|
|
self.update_selections(vec![selection], true, cx);
|
|
|
|
|
}
|
|
|
|
@ -1937,7 +1938,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
pub fn select_line(&mut self, _: &SelectLine, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
let max_point = buffer.max_point();
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
@ -1954,7 +1955,7 @@ impl Editor {
|
|
|
|
|
_: &SplitSelectionIntoLines,
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
|
let mut to_unfold = Vec::new();
|
|
|
|
@ -2002,7 +2003,7 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
fn add_selection(&mut self, above: bool, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let mut selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut state = self.add_selections_state.take().unwrap_or_else(|| {
|
|
|
|
|
let oldest_selection = selections.iter().min_by_key(|s| s.id).unwrap().clone();
|
|
|
|
|
let range = oldest_selection.display_range(&display_map).sorted();
|
|
|
|
@ -2098,7 +2099,7 @@ impl Editor {
|
|
|
|
|
_: &SelectLargerSyntaxNode,
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let old_selections = self.offset_selections(cx).collect::<Box<_>>();
|
|
|
|
|
let old_selections = self.selections::<usize>(cx).collect::<Box<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
|
|
|
|
@ -2156,7 +2157,7 @@ impl Editor {
|
|
|
|
|
_: &MoveToEnclosingBracket,
|
|
|
|
|
cx: &mut ViewContext<Self>,
|
|
|
|
|
) {
|
|
|
|
|
let mut selections = self.offset_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let mut selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
|
|
|
|
let buffer = self.buffer.read(cx.as_ref());
|
|
|
|
|
for selection in &mut selections {
|
|
|
|
|
if let Some((open_range, close_range)) =
|
|
|
|
@ -2227,7 +2228,7 @@ impl Editor {
|
|
|
|
|
let last_selection = buffer
|
|
|
|
|
.selection_set(self.selection_set_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.point_selections(buffer)
|
|
|
|
|
.selections::<Point, _>(buffer)
|
|
|
|
|
.max_by_key(|s| s.id)
|
|
|
|
|
.unwrap();
|
|
|
|
|
last_selection
|
|
|
|
@ -2245,7 +2246,7 @@ impl Editor {
|
|
|
|
|
let selections = buffer
|
|
|
|
|
.selection_set(set_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.point_selections(buffer)
|
|
|
|
|
.selections::<Point, _>(buffer)
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
let start = range.start.to_buffer_point(&display_map, Bias::Left);
|
|
|
|
|
let start_index = self.selection_insertion_index(&selections, start);
|
|
|
|
@ -2282,28 +2283,19 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn point_selections<'a>(
|
|
|
|
|
fn selections<'a, D>(
|
|
|
|
|
&mut self,
|
|
|
|
|
cx: &'a mut ViewContext<Self>,
|
|
|
|
|
) -> impl 'a + Iterator<Item = Selection<Point>> {
|
|
|
|
|
) -> impl 'a + Iterator<Item = Selection<D>>
|
|
|
|
|
where
|
|
|
|
|
D: 'a + TextDimension<'a>,
|
|
|
|
|
{
|
|
|
|
|
self.end_selection(cx);
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
buffer
|
|
|
|
|
.selection_set(self.selection_set_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.point_selections(buffer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn offset_selections<'a>(
|
|
|
|
|
&mut self,
|
|
|
|
|
cx: &'a mut ViewContext<Self>,
|
|
|
|
|
) -> impl 'a + Iterator<Item = Selection<usize>> {
|
|
|
|
|
self.end_selection(cx);
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
buffer
|
|
|
|
|
.selection_set(self.selection_set_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.offset_selections(buffer)
|
|
|
|
|
.selections::<D, _>(buffer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn selection_count(&mut self, cx: &mut ViewContext<Self>) -> usize {
|
|
|
|
@ -2344,7 +2336,7 @@ impl Editor {
|
|
|
|
|
if selections.len() == autoclose_pair_state.ranges.len() {
|
|
|
|
|
selections
|
|
|
|
|
.iter()
|
|
|
|
|
.zip(autoclose_pair_state.ranges.point_ranges(buffer))
|
|
|
|
|
.zip(autoclose_pair_state.ranges.ranges::<Point, _>(buffer))
|
|
|
|
|
.all(|(selection, autoclose_range)| {
|
|
|
|
|
let head = selection.head().to_point(&*buffer);
|
|
|
|
|
autoclose_range.start <= head && autoclose_range.end >= head
|
|
|
|
@ -2404,7 +2396,7 @@ impl Editor {
|
|
|
|
|
pub fn fold(&mut self, _: &Fold, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let mut fold_ranges = Vec::new();
|
|
|
|
|
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
for selection in selections {
|
|
|
|
|
let range = selection.display_range(&display_map).sorted();
|
|
|
|
@ -2427,7 +2419,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn unfold(&mut self, _: &Unfold, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let selections = self.point_selections(cx).collect::<Vec<_>>();
|
|
|
|
|
let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
|
|
|
|
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
|
|
|
|
let buffer = self.buffer.read(cx);
|
|
|
|
|
let ranges = selections
|
|
|
|
@ -2488,7 +2480,7 @@ impl Editor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn fold_selected_ranges(&mut self, _: &FoldSelectedRanges, cx: &mut ViewContext<Self>) {
|
|
|
|
|
let selections = self.point_selections(cx);
|
|
|
|
|
let selections = self.selections::<Point>(cx);
|
|
|
|
|
let ranges = selections.map(|s| s.start..s.end).collect();
|
|
|
|
|
self.fold_ranges(ranges, cx);
|
|
|
|
|
}
|
|
|
|
|