Tidy-up
This commit is contained in:
parent
7f06191c9f
commit
7598030102
6 changed files with 63 additions and 76 deletions
|
@ -2514,7 +2514,6 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
|
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
|
||||||
dbg!("insert!");
|
|
||||||
self.insert_with_autoindent_mode(
|
self.insert_with_autoindent_mode(
|
||||||
text,
|
text,
|
||||||
Some(AutoindentMode::Block {
|
Some(AutoindentMode::Block {
|
||||||
|
|
|
@ -61,10 +61,10 @@ pub fn up_by_rows(
|
||||||
goal: SelectionGoal,
|
goal: SelectionGoal,
|
||||||
preserve_column_at_start: bool,
|
preserve_column_at_start: bool,
|
||||||
) -> (DisplayPoint, SelectionGoal) {
|
) -> (DisplayPoint, SelectionGoal) {
|
||||||
let mut goal_column = if let SelectionGoal::Column(column) = goal {
|
let mut goal_column = match goal {
|
||||||
column
|
SelectionGoal::Column(column) => column,
|
||||||
} else {
|
SelectionGoal::ColumnRange { end, .. } => end,
|
||||||
map.column_to_chars(start.row(), start.column())
|
_ => map.column_to_chars(start.row(), start.column()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let prev_row = start.row().saturating_sub(row_count);
|
let prev_row = start.row().saturating_sub(row_count);
|
||||||
|
@ -95,10 +95,10 @@ pub fn down_by_rows(
|
||||||
goal: SelectionGoal,
|
goal: SelectionGoal,
|
||||||
preserve_column_at_end: bool,
|
preserve_column_at_end: bool,
|
||||||
) -> (DisplayPoint, SelectionGoal) {
|
) -> (DisplayPoint, SelectionGoal) {
|
||||||
let mut goal_column = if let SelectionGoal::Column(column) = goal {
|
let mut goal_column = match goal {
|
||||||
column
|
SelectionGoal::Column(column) => column,
|
||||||
} else {
|
SelectionGoal::ColumnRange { end, .. } => end,
|
||||||
map.column_to_chars(start.row(), start.column())
|
_ => map.column_to_chars(start.row(), start.column()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_row = start.row() + row_count;
|
let new_row = start.row() + row_count;
|
||||||
|
|
|
@ -364,7 +364,6 @@ impl MultiBuffer {
|
||||||
S: ToOffset,
|
S: ToOffset,
|
||||||
T: Into<Arc<str>>,
|
T: Into<Arc<str>>,
|
||||||
{
|
{
|
||||||
dbg!("edit", &autoindent_mode);
|
|
||||||
if self.buffers.borrow().is_empty() {
|
if self.buffers.borrow().is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,5 +520,5 @@ fn encode_ranges(text: &str, point_ranges: &Vec<Range<Point>>) -> String {
|
||||||
byte_range
|
byte_range
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
util::test::generate_marked_text(text, &byte_ranges[..], true);
|
util::test::generate_marked_text(text, &byte_ranges[..], true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,62 +129,37 @@ pub fn visual_block_motion(
|
||||||
|
|
||||||
let was_reversed = tail.column() > head.column();
|
let was_reversed = tail.column() > head.column();
|
||||||
|
|
||||||
if !was_reversed && !(head.column() == 0 && head == map.max_point()) {
|
if !was_reversed && !preserve_goal {
|
||||||
head = movement::saturating_left(map, head);
|
head = movement::saturating_left(map, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((new_head, new_goal)) = move_selection(&map, head, goal) else {
|
let Some((new_head, _)) = move_selection(&map, head, goal) else {
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
head = new_head;
|
head = new_head;
|
||||||
if goal == SelectionGoal::None {
|
|
||||||
goal = new_goal;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut is_reversed = tail.column() > head.column();
|
let is_reversed = tail.column() > head.column();
|
||||||
if was_reversed && !is_reversed {
|
if was_reversed && !is_reversed {
|
||||||
tail = movement::left(map, tail)
|
tail = movement::left(map, tail)
|
||||||
} else if !was_reversed && is_reversed {
|
} else if !was_reversed && is_reversed {
|
||||||
tail = movement::right(map, tail)
|
tail = movement::right(map, tail)
|
||||||
}
|
}
|
||||||
if !is_reversed {
|
if !is_reversed && !preserve_goal {
|
||||||
head = movement::saturating_right(map, head)
|
head = movement::saturating_right(map, head)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !preserve_goal
|
let (start, end) = match goal {
|
||||||
|| !matches!(
|
SelectionGoal::ColumnRange { start, end } if preserve_goal => (start, end),
|
||||||
goal,
|
SelectionGoal::Column(start) if preserve_goal => (start, start + 1),
|
||||||
SelectionGoal::ColumnRange { .. } | SelectionGoal::Column(_)
|
_ => (tail.column(), head.column()),
|
||||||
)
|
|
||||||
{
|
|
||||||
goal = SelectionGoal::ColumnRange {
|
|
||||||
start: tail.column(),
|
|
||||||
end: head.column(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut columns = if let SelectionGoal::ColumnRange { start, end } = goal {
|
|
||||||
if start > end {
|
|
||||||
is_reversed = true;
|
|
||||||
end..start
|
|
||||||
} else {
|
|
||||||
is_reversed = false;
|
|
||||||
start..end
|
|
||||||
}
|
|
||||||
} else if let SelectionGoal::Column(column) = goal {
|
|
||||||
is_reversed = false;
|
|
||||||
column..(column + 1)
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
};
|
||||||
|
goal = SelectionGoal::ColumnRange { start, end };
|
||||||
|
|
||||||
if columns.start >= map.line_len(head.row()) {
|
let columns = if is_reversed {
|
||||||
columns.start = map.line_len(head.row()).saturating_sub(1);
|
head.column()..tail.column()
|
||||||
}
|
} else {
|
||||||
if columns.start >= map.line_len(tail.row()) {
|
tail.column()..head.column()
|
||||||
columns.start = map.line_len(tail.row()).saturating_sub(1);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let mut selections = Vec::new();
|
let mut selections = Vec::new();
|
||||||
let mut row = tail.row();
|
let mut row = tail.row();
|
||||||
|
|
||||||
|
@ -291,37 +266,39 @@ pub fn delete(_: &mut Workspace, _: &VisualDelete, cx: &mut ViewContext<Workspac
|
||||||
let mut original_columns: HashMap<_, _> = Default::default();
|
let mut original_columns: HashMap<_, _> = Default::default();
|
||||||
let line_mode = editor.selections.line_mode;
|
let line_mode = editor.selections.line_mode;
|
||||||
|
|
||||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
editor.transact(cx, |editor, cx| {
|
||||||
s.move_with(|map, selection| {
|
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
if line_mode {
|
s.move_with(|map, selection| {
|
||||||
let mut position = selection.head();
|
if line_mode {
|
||||||
if !selection.reversed {
|
let mut position = selection.head();
|
||||||
position = movement::left(map, position);
|
if !selection.reversed {
|
||||||
|
position = movement::left(map, position);
|
||||||
|
}
|
||||||
|
original_columns.insert(selection.id, position.to_point(map).column);
|
||||||
}
|
}
|
||||||
original_columns.insert(selection.id, position.to_point(map).column);
|
selection.goal = SelectionGoal::None;
|
||||||
}
|
});
|
||||||
selection.goal = SelectionGoal::None;
|
|
||||||
});
|
});
|
||||||
});
|
copy_selections_content(editor, line_mode, cx);
|
||||||
copy_selections_content(editor, line_mode, cx);
|
editor.insert("", cx);
|
||||||
editor.insert("", cx);
|
|
||||||
|
|
||||||
// Fixup cursor position after the deletion
|
// Fixup cursor position after the deletion
|
||||||
editor.set_clip_at_line_ends(true, cx);
|
editor.set_clip_at_line_ends(true, cx);
|
||||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
s.move_with(|map, selection| {
|
s.move_with(|map, selection| {
|
||||||
let mut cursor = selection.head().to_point(map);
|
let mut cursor = selection.head().to_point(map);
|
||||||
|
|
||||||
if let Some(column) = original_columns.get(&selection.id) {
|
if let Some(column) = original_columns.get(&selection.id) {
|
||||||
cursor.column = *column
|
cursor.column = *column
|
||||||
|
}
|
||||||
|
let cursor = map.clip_point(cursor.to_display_point(map), Bias::Left);
|
||||||
|
selection.collapse_to(cursor, selection.goal)
|
||||||
|
});
|
||||||
|
if vim.state.mode == Mode::VisualBlock {
|
||||||
|
s.select_anchors(vec![s.first_anchor()])
|
||||||
}
|
}
|
||||||
let cursor = map.clip_point(cursor.to_display_point(map), Bias::Left);
|
|
||||||
selection.collapse_to(cursor, selection.goal)
|
|
||||||
});
|
});
|
||||||
if vim.state.mode == Mode::VisualBlock {
|
})
|
||||||
s.select_anchors(vec![s.first_anchor()])
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
vim.switch_mode(Mode::Normal, true, cx);
|
vim.switch_mode(Mode::Normal, true, cx);
|
||||||
});
|
});
|
||||||
|
@ -948,8 +925,19 @@ mod test {
|
||||||
"
|
"
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
cx.simulate_shared_keystrokes(["ctrl-v", "down", "down", "down"])
|
cx.simulate_shared_keystrokes(["ctrl-v", "down", "down"])
|
||||||
.await;
|
.await;
|
||||||
|
cx.assert_shared_state(indoc! {
|
||||||
|
"The«ˇ q»uick
|
||||||
|
bro«ˇwn»
|
||||||
|
foxˇ
|
||||||
|
jumps over the
|
||||||
|
|
||||||
|
lazy dog
|
||||||
|
"
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
cx.simulate_shared_keystrokes(["down"]).await;
|
||||||
cx.assert_shared_state(indoc! {
|
cx.assert_shared_state(indoc! {
|
||||||
"The «qˇ»uick
|
"The «qˇ»uick
|
||||||
brow«nˇ»
|
brow«nˇ»
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
{"Key":"ctrl-v"}
|
{"Key":"ctrl-v"}
|
||||||
{"Key":"down"}
|
{"Key":"down"}
|
||||||
{"Key":"down"}
|
{"Key":"down"}
|
||||||
|
{"Get":{"state":"The«ˇ q»uick\nbro«ˇwn»\nfoxˇ\njumps over the\n\nlazy dog\n","mode":"VisualBlock"}}
|
||||||
{"Key":"down"}
|
{"Key":"down"}
|
||||||
{"Get":{"state":"The «qˇ»uick\nbrow«nˇ»\nfox\njump«sˇ» over the\n\nlazy dog\n","mode":"VisualBlock"}}
|
{"Get":{"state":"The «qˇ»uick\nbrow«nˇ»\nfox\njump«sˇ» over the\n\nlazy dog\n","mode":"VisualBlock"}}
|
||||||
{"Key":"left"}
|
{"Key":"left"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue