Get language and project compiling
This commit is contained in:
parent
60a8e74430
commit
ab4f90a20a
4 changed files with 36 additions and 39 deletions
|
@ -2466,3 +2466,9 @@ impl ToPoint for usize {
|
||||||
content.into().visible_text.to_point(*self)
|
content.into().visible_text.to_point(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToPoint for Point {
|
||||||
|
fn to_point<'a>(&self, _: impl Into<Content<'a>>) -> Point {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -522,9 +522,9 @@ impl Buffer {
|
||||||
for request in autoindent_requests {
|
for request in autoindent_requests {
|
||||||
let old_to_new_rows = request
|
let old_to_new_rows = request
|
||||||
.edited
|
.edited
|
||||||
.to_points(&request.before_edit)
|
.points(&request.before_edit)
|
||||||
.map(|point| point.row)
|
.map(|point| point.row)
|
||||||
.zip(request.edited.to_points(&snapshot).map(|point| point.row))
|
.zip(request.edited.points(&snapshot).map(|point| point.row))
|
||||||
.collect::<BTreeMap<u32, u32>>();
|
.collect::<BTreeMap<u32, u32>>();
|
||||||
|
|
||||||
let mut old_suggestions = HashMap::<u32, u32>::default();
|
let mut old_suggestions = HashMap::<u32, u32>::default();
|
||||||
|
@ -633,31 +633,27 @@ impl Buffer {
|
||||||
for selection_set_id in &selection_set_ids {
|
for selection_set_id in &selection_set_ids {
|
||||||
if let Ok(set) = self.selection_set(*selection_set_id) {
|
if let Ok(set) = self.selection_set(*selection_set_id) {
|
||||||
let new_selections = set
|
let new_selections = set
|
||||||
.selections
|
.point_selections(&*self)
|
||||||
.iter()
|
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
let start_point = selection.start.to_point(&self.text);
|
if selection.start.column == 0 {
|
||||||
if start_point.column == 0 {
|
|
||||||
let end_point = selection.end.to_point(&self.text);
|
|
||||||
let delta = Point::new(
|
let delta = Point::new(
|
||||||
0,
|
0,
|
||||||
indent_columns.get(&start_point.row).copied().unwrap_or(0),
|
indent_columns.get(&selection.start.row).copied().unwrap_or(0),
|
||||||
);
|
);
|
||||||
if delta.column > 0 {
|
if delta.column > 0 {
|
||||||
return Selection {
|
return Selection {
|
||||||
id: selection.id,
|
id: selection.id,
|
||||||
goal: selection.goal,
|
goal: selection.goal,
|
||||||
reversed: selection.reversed,
|
reversed: selection.reversed,
|
||||||
start: self
|
start: selection.start + delta,
|
||||||
.anchor_at(start_point + delta, selection.start.bias),
|
end: selection.end + delta,
|
||||||
end: self.anchor_at(end_point + delta, selection.end.bias),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selection.clone()
|
selection
|
||||||
})
|
})
|
||||||
.collect::<Arc<[_]>>();
|
.collect::<Vec<_>>();
|
||||||
self.update_selection_set(*selection_set_id, new_selections, cx)
|
self.update_selection_set(*selection_set_id, &new_selections, cx)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -936,9 +932,9 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_selection_set(
|
pub fn add_selection_set<T: ToOffset>(
|
||||||
&mut self,
|
&mut self,
|
||||||
selections: impl Into<Arc<[Selection]>>,
|
selections: &[Selection<T>],
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> SelectionSetId {
|
) -> SelectionSetId {
|
||||||
let operation = self.text.add_selection_set(selections);
|
let operation = self.text.add_selection_set(selections);
|
||||||
|
@ -952,10 +948,10 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_selection_set(
|
pub fn update_selection_set<T: ToOffset>(
|
||||||
&mut self,
|
&mut self,
|
||||||
set_id: SelectionSetId,
|
set_id: SelectionSetId,
|
||||||
selections: impl Into<Arc<[Selection]>>,
|
selections: &[Selection<T>],
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let operation = self.text.update_selection_set(set_id, selections)?;
|
let operation = self.text.update_selection_set(set_id, selections)?;
|
||||||
|
|
|
@ -275,24 +275,24 @@ fn test_autoindent_moves_selections(cx: &mut MutableAppContext) {
|
||||||
let text = History::new("fn a() {}".into());
|
let text = History::new("fn a() {}".into());
|
||||||
let mut buffer = Buffer::from_history(0, text, None, Some(rust_lang()), cx);
|
let mut buffer = Buffer::from_history(0, text, None, Some(rust_lang()), cx);
|
||||||
|
|
||||||
let selection_set_id = buffer.add_selection_set(Vec::new(), cx);
|
let selection_set_id = buffer.add_selection_set::<usize>(&[], cx);
|
||||||
buffer.start_transaction(Some(selection_set_id)).unwrap();
|
buffer.start_transaction(Some(selection_set_id)).unwrap();
|
||||||
buffer.edit_with_autoindent([5..5, 9..9], "\n\n", cx);
|
buffer.edit_with_autoindent([5..5, 9..9], "\n\n", cx);
|
||||||
buffer
|
buffer
|
||||||
.update_selection_set(
|
.update_selection_set(
|
||||||
selection_set_id,
|
selection_set_id,
|
||||||
vec![
|
&[
|
||||||
Selection {
|
Selection {
|
||||||
id: 0,
|
id: 0,
|
||||||
start: buffer.anchor_before(Point::new(1, 0)),
|
start: Point::new(1, 0),
|
||||||
end: buffer.anchor_before(Point::new(1, 0)),
|
end: Point::new(1, 0),
|
||||||
reversed: false,
|
reversed: false,
|
||||||
goal: SelectionGoal::None,
|
goal: SelectionGoal::None,
|
||||||
},
|
},
|
||||||
Selection {
|
Selection {
|
||||||
id: 1,
|
id: 1,
|
||||||
start: buffer.anchor_before(Point::new(4, 0)),
|
start: Point::new(4, 0),
|
||||||
end: buffer.anchor_before(Point::new(4, 0)),
|
end: Point::new(4, 0),
|
||||||
reversed: false,
|
reversed: false,
|
||||||
goal: SelectionGoal::None,
|
goal: SelectionGoal::None,
|
||||||
},
|
},
|
||||||
|
@ -309,8 +309,7 @@ fn test_autoindent_moves_selections(cx: &mut MutableAppContext) {
|
||||||
let selection_ranges = buffer
|
let selection_ranges = buffer
|
||||||
.selection_set(selection_set_id)
|
.selection_set(selection_set_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.selections
|
.point_selections(&buffer)
|
||||||
.iter()
|
|
||||||
.map(|selection| selection.point_range(&buffer))
|
.map(|selection| selection.point_range(&buffer))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
|
@ -3352,16 +3352,13 @@ mod tests {
|
||||||
let selection_set_id = buffer.update(&mut cx, |buffer, cx| {
|
let selection_set_id = buffer.update(&mut cx, |buffer, cx| {
|
||||||
assert!(!buffer.is_dirty());
|
assert!(!buffer.is_dirty());
|
||||||
buffer.add_selection_set(
|
buffer.add_selection_set(
|
||||||
(0..3)
|
&(0..3)
|
||||||
.map(|row| {
|
.map(|row| Selection {
|
||||||
let anchor = buffer.anchor_at(Point::new(row, 0), Bias::Right);
|
id: row as usize,
|
||||||
Selection {
|
start: Point::new(row, 0),
|
||||||
id: row as usize,
|
end: Point::new(row, 0),
|
||||||
start: anchor.clone(),
|
reversed: false,
|
||||||
end: anchor,
|
goal: SelectionGoal::None,
|
||||||
reversed: false,
|
|
||||||
goal: SelectionGoal::None,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
cx,
|
cx,
|
||||||
|
@ -3391,11 +3388,10 @@ mod tests {
|
||||||
|
|
||||||
let set = buffer.selection_set(selection_set_id).unwrap();
|
let set = buffer.selection_set(selection_set_id).unwrap();
|
||||||
let cursor_positions = set
|
let cursor_positions = set
|
||||||
.selections
|
.point_selections(&*buffer)
|
||||||
.iter()
|
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
assert_eq!(selection.start, selection.end);
|
assert_eq!(selection.start, selection.end);
|
||||||
selection.start.to_point(&*buffer)
|
selection.start
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue