@@ -38,8 +38,8 @@ use std::{
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
-pub fn init(app: &mut MutableAppContext) {
- app.add_bindings(vec![
+pub fn init(cx: &mut MutableAppContext) {
+ cx.add_bindings(vec![
Binding::new("escape", "buffer:cancel", Some("BufferView")),
Binding::new("backspace", "buffer:backspace", Some("BufferView")),
Binding::new("ctrl-h", "buffer:backspace", Some("BufferView")),
@@ -197,104 +197,104 @@ pub fn init(app: &mut MutableAppContext) {
),
]);
- app.add_action("buffer:scroll", Editor::scroll);
- app.add_action("buffer:select", Editor::select);
- app.add_action("buffer:cancel", Editor::cancel);
- app.add_action("buffer:insert", Editor::insert);
- app.add_action("buffer:newline", Editor::newline);
- app.add_action("buffer:backspace", Editor::backspace);
- app.add_action("buffer:delete", Editor::delete);
- app.add_action("buffer:delete_line", Editor::delete_line);
- app.add_action(
+ cx.add_action("buffer:scroll", Editor::scroll);
+ cx.add_action("buffer:select", Editor::select);
+ cx.add_action("buffer:cancel", Editor::cancel);
+ cx.add_action("buffer:insert", Editor::insert);
+ cx.add_action("buffer:newline", Editor::newline);
+ cx.add_action("buffer:backspace", Editor::backspace);
+ cx.add_action("buffer:delete", Editor::delete);
+ cx.add_action("buffer:delete_line", Editor::delete_line);
+ cx.add_action(
"buffer:delete_to_previous_word_boundary",
Editor::delete_to_previous_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:delete_to_next_word_boundary",
Editor::delete_to_next_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:delete_to_beginning_of_line",
Editor::delete_to_beginning_of_line,
);
- app.add_action(
+ cx.add_action(
"buffer:delete_to_end_of_line",
Editor::delete_to_end_of_line,
);
- app.add_action("buffer:duplicate_line", Editor::duplicate_line);
- app.add_action("buffer:move_line_up", Editor::move_line_up);
- app.add_action("buffer:move_line_down", Editor::move_line_down);
- app.add_action("buffer:cut", Editor::cut);
- app.add_action("buffer:copy", Editor::copy);
- app.add_action("buffer:paste", Editor::paste);
- app.add_action("buffer:undo", Editor::undo);
- app.add_action("buffer:redo", Editor::redo);
- app.add_action("buffer:move_up", Editor::move_up);
- app.add_action("buffer:move_down", Editor::move_down);
- app.add_action("buffer:move_left", Editor::move_left);
- app.add_action("buffer:move_right", Editor::move_right);
- app.add_action(
+ cx.add_action("buffer:duplicate_line", Editor::duplicate_line);
+ cx.add_action("buffer:move_line_up", Editor::move_line_up);
+ cx.add_action("buffer:move_line_down", Editor::move_line_down);
+ cx.add_action("buffer:cut", Editor::cut);
+ cx.add_action("buffer:copy", Editor::copy);
+ cx.add_action("buffer:paste", Editor::paste);
+ cx.add_action("buffer:undo", Editor::undo);
+ cx.add_action("buffer:redo", Editor::redo);
+ cx.add_action("buffer:move_up", Editor::move_up);
+ cx.add_action("buffer:move_down", Editor::move_down);
+ cx.add_action("buffer:move_left", Editor::move_left);
+ cx.add_action("buffer:move_right", Editor::move_right);
+ cx.add_action(
"buffer:move_to_previous_word_boundary",
Editor::move_to_previous_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:move_to_next_word_boundary",
Editor::move_to_next_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:move_to_beginning_of_line",
Editor::move_to_beginning_of_line,
);
- app.add_action("buffer:move_to_end_of_line", Editor::move_to_end_of_line);
- app.add_action("buffer:move_to_beginning", Editor::move_to_beginning);
- app.add_action("buffer:move_to_end", Editor::move_to_end);
- app.add_action("buffer:select_up", Editor::select_up);
- app.add_action("buffer:select_down", Editor::select_down);
- app.add_action("buffer:select_left", Editor::select_left);
- app.add_action("buffer:select_right", Editor::select_right);
- app.add_action(
+ cx.add_action("buffer:move_to_end_of_line", Editor::move_to_end_of_line);
+ cx.add_action("buffer:move_to_beginning", Editor::move_to_beginning);
+ cx.add_action("buffer:move_to_end", Editor::move_to_end);
+ cx.add_action("buffer:select_up", Editor::select_up);
+ cx.add_action("buffer:select_down", Editor::select_down);
+ cx.add_action("buffer:select_left", Editor::select_left);
+ cx.add_action("buffer:select_right", Editor::select_right);
+ cx.add_action(
"buffer:select_to_previous_word_boundary",
Editor::select_to_previous_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:select_to_next_word_boundary",
Editor::select_to_next_word_boundary,
);
- app.add_action(
+ cx.add_action(
"buffer:select_to_beginning_of_line",
Editor::select_to_beginning_of_line,
);
- app.add_action(
+ cx.add_action(
"buffer:select_to_end_of_line",
Editor::select_to_end_of_line,
);
- app.add_action("buffer:select_to_beginning", Editor::select_to_beginning);
- app.add_action("buffer:select_to_end", Editor::select_to_end);
- app.add_action("buffer:select_all", Editor::select_all);
- app.add_action("buffer:select_line", Editor::select_line);
- app.add_action(
+ cx.add_action("buffer:select_to_beginning", Editor::select_to_beginning);
+ cx.add_action("buffer:select_to_end", Editor::select_to_end);
+ cx.add_action("buffer:select_all", Editor::select_all);
+ cx.add_action("buffer:select_line", Editor::select_line);
+ cx.add_action(
"buffer:split_selection_into_lines",
Editor::split_selection_into_lines,
);
- app.add_action("buffer:add_selection_above", Editor::add_selection_above);
- app.add_action("buffer:add_selection_below", Editor::add_selection_below);
- app.add_action(
+ cx.add_action("buffer:add_selection_above", Editor::add_selection_above);
+ cx.add_action("buffer:add_selection_below", Editor::add_selection_below);
+ cx.add_action(
"buffer:select_larger_syntax_node",
Editor::select_larger_syntax_node,
);
- app.add_action(
+ cx.add_action(
"buffer:select_smaller_syntax_node",
Editor::select_smaller_syntax_node,
);
- app.add_action(
+ cx.add_action(
"buffer:move_to_enclosing_bracket",
Editor::move_to_enclosing_bracket,
);
- app.add_action("buffer:page_up", Editor::page_up);
- app.add_action("buffer:page_down", Editor::page_down);
- app.add_action("buffer:fold", Editor::fold);
- app.add_action("buffer:unfold", Editor::unfold);
- app.add_action("buffer:fold_selected_ranges", Editor::fold_selected_ranges);
+ cx.add_action("buffer:page_up", Editor::page_up);
+ cx.add_action("buffer:page_down", Editor::page_down);
+ cx.add_action("buffer:fold", Editor::fold);
+ cx.add_action("buffer:unfold", Editor::unfold);
+ cx.add_action("buffer:fold_selected_ranges", Editor::fold_selected_ranges);
}
pub enum SelectAction {
@@ -340,9 +340,9 @@ struct ClipboardSelection {
}
impl Editor {
- pub fn single_line(settings: watch::Receiver<Settings>, ctx: &mut ViewContext<Self>) -> Self {
- let buffer = ctx.add_model(|ctx| Buffer::new(0, String::new(), ctx));
- let mut view = Self::for_buffer(buffer, settings, ctx);
+ pub fn single_line(settings: watch::Receiver<Settings>, cx: &mut ViewContext<Self>) -> Self {
+ let buffer = cx.add_model(|cx| Buffer::new(0, String::new(), cx));
+ let mut view = Self::for_buffer(buffer, settings, cx);
view.single_line = true;
view
}
@@ -350,14 +350,14 @@ impl Editor {
pub fn for_buffer(
buffer: ModelHandle<Buffer>,
settings: watch::Receiver<Settings>,
- ctx: &mut ViewContext<Self>,
+ cx: &mut ViewContext<Self>,
) -> Self {
- ctx.observe_model(&buffer, Self::on_buffer_changed);
- ctx.subscribe_to_model(&buffer, Self::on_buffer_event);
- let display_map = DisplayMap::new(buffer.clone(), settings.borrow().tab_size, ctx.as_ref());
+ cx.observe_model(&buffer, Self::on_buffer_changed);
+ cx.subscribe_to_model(&buffer, Self::on_buffer_event);
+ let display_map = DisplayMap::new(buffer.clone(), settings.borrow().tab_size, cx.as_ref());
let mut next_selection_id = 0;
- let (selection_set_id, _) = buffer.update(ctx, |buffer, ctx| {
+ let (selection_set_id, _) = buffer.update(cx, |buffer, cx| {
buffer.add_selection_set(
vec![Selection {
id: post_inc(&mut next_selection_id),
@@ -366,11 +366,11 @@ impl Editor {
reversed: false,
goal: SelectionGoal::None,
}],
- Some(ctx),
+ Some(cx),
)
});
Self {
- handle: ctx.handle().downgrade(),
+ handle: cx.handle().downgrade(),
buffer,
display_map,
selection_set_id,
@@ -397,9 +397,9 @@ impl Editor {
!self.single_line
}
- fn scroll(&mut self, scroll_position: &Vector2F, ctx: &mut ViewContext<Self>) {
+ fn scroll(&mut self, scroll_position: &Vector2F, cx: &mut ViewContext<Self>) {
*self.scroll_position.lock() = *scroll_position;
- ctx.notify();
+ cx.notify();
}
pub fn scroll_position(&self) -> Vector2F {
@@ -416,11 +416,11 @@ impl Editor {
&self,
viewport_height: f32,
line_height: f32,
- app: &AppContext,
+ cx: &AppContext,
) -> bool {
let mut scroll_position = self.scroll_position.lock();
let scroll_top = scroll_position.y();
- scroll_position.set_y(scroll_top.min(self.max_point(app).row().saturating_sub(1) as f32));
+ scroll_position.set_y(scroll_top.min(self.max_point(cx).row().saturating_sub(1) as f32));
let mut autoscroll_requested = self.autoscroll_requested.lock();
if *autoscroll_requested {
@@ -431,18 +431,18 @@ impl Editor {
let visible_lines = viewport_height / line_height;
let first_cursor_top = self
- .selections(app)
+ .selections(cx)
.first()
.unwrap()
.head()
- .to_display_point(&self.display_map, app)
+ .to_display_point(&self.display_map, cx)
.row() as f32;
let last_cursor_bottom = self
- .selections(app)
+ .selections(cx)
.last()
.unwrap()
.head()
- .to_display_point(&self.display_map, app)
+ .to_display_point(&self.display_map, cx)
.row() as f32
+ 1.0;
@@ -474,17 +474,14 @@ impl Editor {
scroll_width: f32,
max_glyph_width: f32,
layouts: &[text_layout::Line],
- ctx: &AppContext,
+ cx: &AppContext,
) {
let mut target_left = std::f32::INFINITY;
let mut target_right = 0.0_f32;
- for selection in self.selections(ctx) {
- let head = selection.head().to_display_point(&self.display_map, ctx);
+ for selection in self.selections(cx) {
+ let head = selection.head().to_display_point(&self.display_map, cx);
let start_column = head.column().saturating_sub(3);
- let end_column = cmp::min(
- self.display_map.line_len(head.row(), ctx),
- head.column() + 3,
- );
+ let end_column = cmp::min(self.display_map.line_len(head.row(), cx), head.column() + 3);
target_left = target_left
.min(layouts[(head.row() - start_row) as usize].x_for_index(start_column as usize));
target_right = target_right.max(
@@ -509,26 +506,26 @@ impl Editor {
}
}
- fn select(&mut self, arg: &SelectAction, ctx: &mut ViewContext<Self>) {
+ fn select(&mut self, arg: &SelectAction, cx: &mut ViewContext<Self>) {
match arg {
- SelectAction::Begin { position, add } => self.begin_selection(*position, *add, ctx),
+ SelectAction::Begin { position, add } => self.begin_selection(*position, *add, cx),
SelectAction::Update {
position,
scroll_position,
- } => self.update_selection(*position, *scroll_position, ctx),
- SelectAction::End => self.end_selection(ctx),
+ } => self.update_selection(*position, *scroll_position, cx),
+ SelectAction::End => self.end_selection(cx),
}
}
- fn begin_selection(&mut self, position: DisplayPoint, add: bool, ctx: &mut ViewContext<Self>) {
+ fn begin_selection(&mut self, position: DisplayPoint, add: bool, cx: &mut ViewContext<Self>) {
if !self.focused {
- ctx.focus_self();
- ctx.emit(Event::Activate);
+ cx.focus_self();
+ cx.emit(Event::Activate);
}
let cursor = self
.display_map
- .anchor_before(position, Bias::Left, ctx.as_ref());
+ .anchor_before(position, Bias::Left, cx.as_ref());
let selection = Selection {
id: post_inc(&mut self.next_selection_id),
start: cursor.clone(),
@@ -538,23 +535,23 @@ impl Editor {
};
if !add {
- self.update_selections(Vec::new(), false, ctx);
+ self.update_selections(Vec::new(), false, cx);
}
self.pending_selection = Some(selection);
- ctx.notify();
+ cx.notify();
}
fn update_selection(
&mut self,
position: DisplayPoint,
scroll_position: Vector2F,
- ctx: &mut ViewContext<Self>,
+ cx: &mut ViewContext<Self>,
) {
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
let cursor = self
.display_map
- .anchor_before(position, Bias::Left, ctx.as_ref());
+ .anchor_before(position, Bias::Left, cx.as_ref());
if let Some(selection) = self.pending_selection.as_mut() {
selection.set_head(buffer, cursor);
} else {
@@ -564,15 +561,15 @@ impl Editor {
*self.scroll_position.lock() = scroll_position;
- ctx.notify();
+ cx.notify();
}
- fn end_selection(&mut self, ctx: &mut ViewContext<Self>) {
+ fn end_selection(&mut self, cx: &mut ViewContext<Self>) {
if let Some(selection) = self.pending_selection.take() {
- let ix = self.selection_insertion_index(&selection.start, ctx.as_ref());
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ let ix = self.selection_insertion_index(&selection.start, cx.as_ref());
+ let mut selections = self.selections(cx.as_ref()).to_vec();
selections.insert(ix, selection);
- self.update_selections(selections, false, ctx);
+ self.update_selections(selections, false, cx);
} else {
log::error!("end_selection dispatched with no pending selection");
}
@@ -582,11 +579,11 @@ impl Editor {
self.pending_selection.is_some()
}
- pub fn cancel(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let selections = self.selections(ctx.as_ref());
+ pub fn cancel(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let selections = self.selections(cx.as_ref());
if let Some(pending_selection) = self.pending_selection.take() {
if selections.is_empty() {
- self.update_selections(vec![pending_selection], true, ctx);
+ self.update_selections(vec![pending_selection], true, cx);
}
} else {
let mut oldest_selection = selections.iter().min_by_key(|s| s.id).unwrap().clone();
@@ -594,16 +591,16 @@ impl Editor {
oldest_selection.start = oldest_selection.head().clone();
oldest_selection.end = oldest_selection.head().clone();
}
- self.update_selections(vec![oldest_selection], true, ctx);
+ self.update_selections(vec![oldest_selection], true, cx);
}
}
- fn select_ranges<I, T>(&mut self, ranges: I, autoscroll: bool, ctx: &mut ViewContext<Self>)
+ fn select_ranges<I, T>(&mut self, ranges: I, autoscroll: bool, cx: &mut ViewContext<Self>)
where
I: IntoIterator<Item = Range<T>>,
T: ToOffset,
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
let mut selections = Vec::new();
for range in ranges {
let mut start = range.start.to_offset(buffer);
@@ -622,11 +619,11 @@ impl Editor {
goal: SelectionGoal::None,
});
}
- self.update_selections(selections, autoscroll, ctx);
+ self.update_selections(selections, autoscroll, cx);
}
#[cfg(test)]
- fn select_display_ranges<'a, T>(&mut self, ranges: T, ctx: &mut ViewContext<Self>) -> Result<()>
+ fn select_display_ranges<'a, T>(&mut self, ranges: T, cx: &mut ViewContext<Self>) -> Result<()>
where
T: IntoIterator<Item = &'a Range<DisplayPoint>>,
{
@@ -645,34 +642,32 @@ impl Editor {
id: post_inc(&mut self.next_selection_id),
start: self
.display_map
- .anchor_before(start, Bias::Left, ctx.as_ref()),
- end: self
- .display_map
- .anchor_before(end, Bias::Left, ctx.as_ref()),
+ .anchor_before(start, Bias::Left, cx.as_ref()),
+ end: self.display_map.anchor_before(end, Bias::Left, cx.as_ref()),
reversed,
goal: SelectionGoal::None,
});
}
- self.update_selections(selections, false, ctx);
+ self.update_selections(selections, false, cx);
Ok(())
}
- pub fn insert(&mut self, text: &String, ctx: &mut ViewContext<Self>) {
+ pub fn insert(&mut self, text: &String, cx: &mut ViewContext<Self>) {
let mut old_selections = SmallVec::<[_; 32]>::new();
{
- let buffer = self.buffer.read(ctx);
- for selection in self.selections(ctx.as_ref()) {
+ let buffer = self.buffer.read(cx);
+ for selection in self.selections(cx.as_ref()) {
let start = selection.start.to_offset(buffer);
let end = selection.end.to_offset(buffer);
old_selections.push((selection.id, start..end));
}
}
- self.start_transaction(ctx);
+ self.start_transaction(cx);
let mut new_selections = Vec::new();
- self.buffer.update(ctx, |buffer, ctx| {
+ self.buffer.update(cx, |buffer, cx| {
let edit_ranges = old_selections.iter().map(|(_, range)| range.clone());
- if let Err(error) = buffer.edit(edit_ranges, text.as_str(), Some(ctx)) {
+ if let Err(error) = buffer.edit(edit_ranges, text.as_str(), Some(cx)) {
log::error!("error inserting text: {}", error);
};
let text_len = text.len() as isize;
@@ -696,33 +691,33 @@ impl Editor {
.collect();
});
- self.update_selections(new_selections, true, ctx);
- self.end_transaction(ctx);
+ self.update_selections(new_selections, true, cx);
+ self.end_transaction(cx);
}
- fn newline(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
+ fn newline(&mut self, _: &(), cx: &mut ViewContext<Self>) {
if self.single_line {
- ctx.propagate_action();
+ cx.propagate_action();
} else {
- self.insert(&"\n".into(), ctx);
+ self.insert(&"\n".into(), cx);
}
}
- pub fn backspace(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn backspace(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
let range = selection.point_range(buffer);
if range.start == range.end {
let head = selection
.head()
- .to_display_point(&self.display_map, ctx.as_ref());
+ .to_display_point(&self.display_map, cx.as_ref());
let cursor = self.display_map.anchor_before(
- movement::left(&self.display_map, head, ctx.as_ref()).unwrap(),
+ movement::left(&self.display_map, head, cx.as_ref()).unwrap(),
Bias::Left,
- ctx.as_ref(),
+ cx.as_ref(),
);
selection.set_head(&buffer, cursor);
selection.goal = SelectionGoal::None;
@@ -730,26 +725,26 @@ impl Editor {
}
}
- self.update_selections(selections, true, ctx);
- self.insert(&String::new(), ctx);
- self.end_transaction(ctx);
+ self.update_selections(selections, true, cx);
+ self.insert(&String::new(), cx);
+ self.end_transaction(cx);
}
- pub fn delete(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn delete(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
let range = selection.point_range(buffer);
if range.start == range.end {
let head = selection
.head()
- .to_display_point(&self.display_map, ctx.as_ref());
+ .to_display_point(&self.display_map, cx.as_ref());
let cursor = self.display_map.anchor_before(
- movement::right(&self.display_map, head, ctx.as_ref()).unwrap(),
+ movement::right(&self.display_map, head, cx.as_ref()).unwrap(),
Bias::Right,
- ctx.as_ref(),
+ cx.as_ref(),
);
selection.set_head(&buffer, cursor);
selection.goal = SelectionGoal::None;
@@ -757,15 +752,15 @@ impl Editor {
}
}
- self.update_selections(selections, true, ctx);
- self.insert(&String::new(), ctx);
- self.end_transaction(ctx);
+ self.update_selections(selections, true, cx);
+ self.insert(&String::new(), cx);
+ self.end_transaction(cx);
}
- pub fn delete_line(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
+ pub fn delete_line(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
- let app = ctx.as_ref();
+ let app = cx.as_ref();
let buffer = self.buffer.read(app);
let mut new_cursors = Vec::new();
@@ -837,29 +832,29 @@ impl Editor {
})
.collect();
self.buffer
- .update(ctx, |buffer, ctx| buffer.edit(edit_ranges, "", Some(ctx)))
+ .update(cx, |buffer, cx| buffer.edit(edit_ranges, "", Some(cx)))
.unwrap();
- self.update_selections(new_selections, true, ctx);
- self.end_transaction(ctx);
+ self.update_selections(new_selections, true, cx);
+ self.end_transaction(cx);
}
- pub fn duplicate_line(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
+ pub fn duplicate_line(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
// Temporarily bias selections right to allow newly duplicate lines to push them down
// when the selections are at the beginning of a line.
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
selection.start = selection.start.bias_right(buffer);
selection.end = selection.end.bias_right(buffer);
}
}
- self.update_selections(selections.clone(), false, ctx);
+ self.update_selections(selections.clone(), false, cx);
- let app = ctx.as_ref();
- let buffer = self.buffer.read(ctx);
+ let app = cx.as_ref();
+ let buffer = self.buffer.read(cx);
let mut edits = Vec::new();
let mut selections_iter = selections.iter_mut().peekable();
@@ -888,28 +883,28 @@ impl Editor {
edits.push((start, text));
}
- self.buffer.update(ctx, |buffer, ctx| {
+ self.buffer.update(cx, |buffer, cx| {
for (offset, text) in edits.into_iter().rev() {
- buffer.edit(Some(offset..offset), text, Some(ctx)).unwrap();
+ buffer.edit(Some(offset..offset), text, Some(cx)).unwrap();
}
});
// Restore bias on selections.
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
selection.start = selection.start.bias_left(buffer);
selection.end = selection.end.bias_left(buffer);
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
- self.end_transaction(ctx);
+ self.end_transaction(cx);
}
- pub fn move_line_up(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
+ pub fn move_line_up(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
- let app = ctx.as_ref();
- let buffer = self.buffer.read(ctx);
+ let app = cx.as_ref();
+ let buffer = self.buffer.read(cx);
let mut edits = Vec::new();
let mut new_selection_ranges = Vec::new();
@@ -977,23 +972,23 @@ impl Editor {
new_selection_ranges.extend(contiguous_selections.drain(..));
}
- self.unfold_ranges(old_folds, ctx);
- self.buffer.update(ctx, |buffer, ctx| {
+ self.unfold_ranges(old_folds, cx);
+ self.buffer.update(cx, |buffer, cx| {
for (range, text) in edits.into_iter().rev() {
- buffer.edit(Some(range), text, Some(ctx)).unwrap();
+ buffer.edit(Some(range), text, Some(cx)).unwrap();
}
});
- self.fold_ranges(new_folds, ctx);
- self.select_ranges(new_selection_ranges, true, ctx);
+ self.fold_ranges(new_folds, cx);
+ self.select_ranges(new_selection_ranges, true, cx);
- self.end_transaction(ctx);
+ self.end_transaction(cx);
}
- pub fn move_line_down(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
+ pub fn move_line_down(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
- let app = ctx.as_ref();
- let buffer = self.buffer.read(ctx);
+ let app = cx.as_ref();
+ let buffer = self.buffer.read(cx);
let mut edits = Vec::new();
let mut new_selection_ranges = Vec::new();
@@ -1065,25 +1060,25 @@ impl Editor {
new_selection_ranges.extend(contiguous_selections.drain(..));
}
- self.unfold_ranges(old_folds, ctx);
- self.buffer.update(ctx, |buffer, ctx| {
+ self.unfold_ranges(old_folds, cx);
+ self.buffer.update(cx, |buffer, cx| {
for (range, text) in edits.into_iter().rev() {
- buffer.edit(Some(range), text, Some(ctx)).unwrap();
+ buffer.edit(Some(range), text, Some(cx)).unwrap();
}
});
- self.fold_ranges(new_folds, ctx);
- self.select_ranges(new_selection_ranges, true, ctx);
+ self.fold_ranges(new_folds, cx);
+ self.select_ranges(new_selection_ranges, true, cx);
- self.end_transaction(ctx);
+ self.end_transaction(cx);
}
- pub fn cut(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.start_transaction(ctx);
+ pub fn cut(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.start_transaction(cx);
let mut text = String::new();
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ let mut selections = self.selections(cx.as_ref()).to_vec();
let mut clipboard_selections = Vec::with_capacity(selections.len());
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
let max_point = buffer.max_point();
for selection in &mut selections {
let mut start = selection.start.to_point(buffer);
@@ -1106,19 +1101,19 @@ impl Editor {
});
}
}
- self.update_selections(selections, true, ctx);
- self.insert(&String::new(), ctx);
- self.end_transaction(ctx);
+ self.update_selections(selections, true, cx);
+ self.insert(&String::new(), cx);
+ self.end_transaction(cx);
- ctx.as_mut()
+ cx.as_mut()
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
}
- pub fn copy(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let buffer = self.buffer.read(ctx);
+ pub fn copy(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let buffer = self.buffer.read(cx);
let max_point = buffer.max_point();
let mut text = String::new();
- let selections = self.selections(ctx.as_ref());
+ let selections = self.selections(cx.as_ref());
let mut clipboard_selections = Vec::with_capacity(selections.len());
for selection in selections {
let mut start = selection.start.to_point(buffer);
@@ -1139,15 +1134,15 @@ impl Editor {
});
}
- ctx.as_mut()
+ cx.as_mut()
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
}
- pub fn paste(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- if let Some(item) = ctx.as_mut().read_from_clipboard() {
+ pub fn paste(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ 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 selections = self.selections(ctx.as_ref()).to_vec();
+ let selections = self.selections(cx.as_ref()).to_vec();
if clipboard_selections.len() != selections.len() {
let merged_selection = ClipboardSelection {
len: clipboard_selections.iter().map(|s| s.len).sum(),
@@ -1157,7 +1152,7 @@ impl Editor {
clipboard_selections.push(merged_selection);
}
- self.start_transaction(ctx);
+ self.start_transaction(cx);
let mut new_selections = Vec::with_capacity(selections.len());
let mut clipboard_chars = clipboard_text.chars().cycle();
for (selection, clipboard_selection) in
@@ -1166,7 +1161,7 @@ impl Editor {
let to_insert =
String::from_iter(clipboard_chars.by_ref().take(clipboard_selection.len));
- self.buffer.update(ctx, |buffer, ctx| {
+ self.buffer.update(cx, |buffer, cx| {
let selection_start = selection.start.to_point(buffer);
let selection_end = selection.end.to_point(buffer);
@@ -1178,11 +1173,11 @@ impl Editor {
if selection_start == selection_end && clipboard_selection.is_entire_line {
let line_start = Point::new(selection_start.row, 0);
buffer
- .edit(Some(line_start..line_start), to_insert, Some(ctx))
+ .edit(Some(line_start..line_start), to_insert, Some(cx))
.unwrap();
} else {
buffer
- .edit(Some(&selection.start..&selection.end), to_insert, Some(ctx))
+ .edit(Some(&selection.start..&selection.end), to_insert, Some(cx))
.unwrap();
};
@@ -1196,26 +1191,24 @@ impl Editor {
});
});
}
- self.update_selections(new_selections, true, ctx);
- self.end_transaction(ctx);
+ self.update_selections(new_selections, true, cx);
+ self.end_transaction(cx);
} else {
- self.insert(clipboard_text, ctx);
+ self.insert(clipboard_text, cx);
}
}
}
- pub fn undo(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.buffer
- .update(ctx, |buffer, ctx| buffer.undo(Some(ctx)));
+ pub fn undo(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.buffer.update(cx, |buffer, cx| buffer.undo(Some(cx)));
}
- pub fn redo(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- self.buffer
- .update(ctx, |buffer, ctx| buffer.redo(Some(ctx)));
+ pub fn redo(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ self.buffer.update(cx, |buffer, cx| buffer.redo(Some(cx)));
}
- pub fn move_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let app = ctx.as_ref();
+ pub fn move_left(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let app = cx.as_ref();
let mut selections = self.selections(app).to_vec();
{
for selection in &mut selections {
@@ -1237,33 +1230,33 @@ impl Editor {
selection.goal = SelectionGoal::None;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn select_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn select_left(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
let head = selection
.head()
- .to_display_point(&self.display_map, ctx.as_ref());
+ .to_display_point(&self.display_map, cx.as_ref());
let cursor = self.display_map.anchor_before(
- movement::left(&self.display_map, head, ctx.as_ref()).unwrap(),
+ movement::left(&self.display_map, head, cx.as_ref()).unwrap(),
Bias::Left,
- ctx.as_ref(),
+ cx.as_ref(),
);
selection.set_head(&buffer, cursor);
selection.goal = SelectionGoal::None;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn move_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn move_right(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
for selection in &mut selections {
let start = selection.start.to_display_point(&self.display_map, app);
let end = selection.end.to_display_point(&self.display_map, app);
@@ -1283,18 +1276,18 @@ impl Editor {
selection.goal = SelectionGoal::None;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn select_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn select_right(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
let buffer = self.buffer.read(app);
for selection in &mut selections {
let head = selection
.head()
- .to_display_point(&self.display_map, ctx.as_ref());
+ .to_display_point(&self.display_map, cx.as_ref());
let cursor = self.display_map.anchor_before(
movement::right(&self.display_map, head, app).unwrap(),
Bias::Right,
@@ -1304,16 +1297,16 @@ impl Editor {
selection.goal = SelectionGoal::None;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn move_up(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
+ pub fn move_up(&mut self, _: &(), cx: &mut ViewContext<Self>) {
if self.single_line {
- ctx.propagate_action();
+ cx.propagate_action();
} else {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
for selection in &mut selections {
let start = selection.start.to_display_point(&self.display_map, app);
let end = selection.end.to_display_point(&self.display_map, app);
@@ -1330,14 +1323,14 @@ impl Editor {
selection.reversed = false;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
}
- pub fn select_up(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn select_up(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
let buffer = self.buffer.read(app);
for selection in &mut selections {
let head = selection.head().to_display_point(&self.display_map, app);
@@ -1350,16 +1343,16 @@ impl Editor {
selection.goal = goal;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn move_down(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
+ pub fn move_down(&mut self, _: &(), cx: &mut ViewContext<Self>) {
if self.single_line {
- ctx.propagate_action();
+ cx.propagate_action();
} else {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
for selection in &mut selections {
let start = selection.start.to_display_point(&self.display_map, app);
let end = selection.end.to_display_point(&self.display_map, app);
@@ -1376,14 +1369,14 @@ impl Editor {
selection.reversed = false;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
}
- pub fn select_down(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let mut selections = self.selections(ctx.as_ref()).to_vec();
+ pub fn select_down(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let mut selections = self.selections(cx.as_ref()).to_vec();
{
- let app = ctx.as_ref();
+ let app = cx.as_ref();
let buffer = self.buffer.read(app);
for selection in &mut selections {
let head = selection.head().to_display_point(&self.display_map, app);
@@ -1396,11 +1389,11 @@ impl Editor {
selection.goal = goal;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn move_to_previous_word_boundary(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let app = ctx.as_ref();
+ pub fn move_to_previous_word_boundary(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let app = cx.as_ref();
let mut selections = self.selections(app).to_vec();
{
for selection in &mut selections {
@@ -1413,14 +1406,14 @@ impl Editor {
selection.goal = SelectionGoal::None;
}
}
- self.update_selections(selections, true, ctx);
+ self.update_selections(selections, true, cx);
}
- pub fn select_to_previous_word_boundary(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
- let app = ctx.as_ref();
+ pub fn select_to_previous_word_boundary(&mut self, _: &(), cx: &mut ViewContext<Self>) {
+ let app = cx.as_ref();
let mut selections = self.selections(app).to_vec();
{
- let buffer = self.buffer.read(ctx);
+ let buffer = self.buffer.read(cx);
for selection in &mut selections {
let head = selection.head().to_display_point(&self.display_map, app);
let new_head = movement::prev_word_boundary(&self.display_map, head, app).unwrap();