First pass on fixes
This commit is contained in:
parent
5826d89b97
commit
2f3be75fc7
269 changed files with 1593 additions and 2574 deletions
|
@ -510,8 +510,8 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
vim.switch_mode(Mode::Normal, true, window, cx);
|
||||
}
|
||||
vim.update_editor(cx, |_, editor, cx| {
|
||||
if let Some(first_sel) = initial_selections {
|
||||
if let Some(tx_id) = editor
|
||||
if let Some(first_sel) = initial_selections
|
||||
&& let Some(tx_id) = editor
|
||||
.buffer()
|
||||
.update(cx, |multi, cx| multi.last_transaction_id(cx))
|
||||
{
|
||||
|
@ -521,7 +521,6 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
|||
old.1 = Some(last_sel);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.ok();
|
||||
|
@ -1713,15 +1712,12 @@ impl Vim {
|
|||
match c {
|
||||
'%' => {
|
||||
self.update_editor(cx, |_, editor, cx| {
|
||||
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
|
||||
if let Some(file) = buffer.read(cx).file() {
|
||||
if let Some(local) = file.as_local() {
|
||||
if let Some(str) = local.path().to_str() {
|
||||
if let Some((_, buffer, _)) = editor.active_excerpt(cx)
|
||||
&& let Some(file) = buffer.read(cx).file()
|
||||
&& let Some(local) = file.as_local()
|
||||
&& let Some(str) = local.path().to_str() {
|
||||
ret.push_str(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
'!' => {
|
||||
|
@ -1954,8 +1950,8 @@ impl ShellExec {
|
|||
return;
|
||||
};
|
||||
|
||||
if let Some(mut stdin) = running.stdin.take() {
|
||||
if let Some(snapshot) = input_snapshot {
|
||||
if let Some(mut stdin) = running.stdin.take()
|
||||
&& let Some(snapshot) = input_snapshot {
|
||||
let range = range.clone();
|
||||
cx.background_spawn(async move {
|
||||
for chunk in snapshot.text_for_range(range) {
|
||||
|
@ -1966,8 +1962,7 @@ impl ShellExec {
|
|||
stdin.flush().log_err();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let output = cx
|
||||
.background_spawn(async move { running.wait_with_output() })
|
||||
|
|
|
@ -63,8 +63,8 @@ impl Vim {
|
|||
}
|
||||
|
||||
fn literal(&mut self, action: &Literal, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(Operator::Literal { prefix }) = self.active_operator() {
|
||||
if let Some(prefix) = prefix {
|
||||
if let Some(Operator::Literal { prefix }) = self.active_operator()
|
||||
&& let Some(prefix) = prefix {
|
||||
if let Some(keystroke) = Keystroke::parse(&action.0).ok() {
|
||||
window.defer(cx, |window, cx| {
|
||||
window.dispatch_keystroke(keystroke, cx);
|
||||
|
@ -72,7 +72,6 @@ impl Vim {
|
|||
}
|
||||
return self.handle_literal_input(prefix, "", window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
self.insert_literal(Some(action.1), "", window, cx);
|
||||
}
|
||||
|
|
|
@ -1811,11 +1811,10 @@ fn previous_word_end(
|
|||
.ignore_punctuation(ignore_punctuation);
|
||||
let mut point = point.to_point(map);
|
||||
|
||||
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row)) {
|
||||
if let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
|
||||
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row))
|
||||
&& let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
|
||||
point.column += ch.len_utf8() as u32;
|
||||
}
|
||||
}
|
||||
for _ in 0..times {
|
||||
let new_point = movement::find_preceding_boundary_point(
|
||||
&map.buffer_snapshot,
|
||||
|
@ -1986,11 +1985,10 @@ fn previous_subword_end(
|
|||
.ignore_punctuation(ignore_punctuation);
|
||||
let mut point = point.to_point(map);
|
||||
|
||||
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row)) {
|
||||
if let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
|
||||
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row))
|
||||
&& let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
|
||||
point.column += ch.len_utf8() as u32;
|
||||
}
|
||||
}
|
||||
for _ in 0..times {
|
||||
let new_point = movement::find_preceding_boundary_point(
|
||||
&map.buffer_snapshot,
|
||||
|
@ -2054,11 +2052,10 @@ pub(crate) fn last_non_whitespace(
|
|||
let classifier = map.buffer_snapshot.char_classifier_at(from.to_point(map));
|
||||
|
||||
// NOTE: depending on clip_at_line_end we may already be one char back from the end.
|
||||
if let Some((ch, _)) = map.buffer_chars_at(end_of_line).next() {
|
||||
if classifier.kind(ch) != CharKind::Whitespace {
|
||||
if let Some((ch, _)) = map.buffer_chars_at(end_of_line).next()
|
||||
&& classifier.kind(ch) != CharKind::Whitespace {
|
||||
return end_of_line.to_display_point(map);
|
||||
}
|
||||
}
|
||||
|
||||
for (ch, offset) in map.reverse_buffer_chars_at(end_of_line) {
|
||||
if ch == '\n' {
|
||||
|
|
|
@ -74,11 +74,10 @@ impl Vim {
|
|||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut cursor = selection.head();
|
||||
if kind.linewise() {
|
||||
if let Some(column) = original_columns.get(&selection.id) {
|
||||
if kind.linewise()
|
||||
&& let Some(column) = original_columns.get(&selection.id) {
|
||||
*cursor.column_mut() = *column
|
||||
}
|
||||
}
|
||||
cursor = map.clip_point(cursor, Bias::Left);
|
||||
selection.collapse_to(cursor, selection.goal)
|
||||
});
|
||||
|
|
|
@ -256,11 +256,10 @@ impl Vim {
|
|||
}
|
||||
});
|
||||
|
||||
if should_jump {
|
||||
if let Some(anchor) = anchor {
|
||||
if should_jump
|
||||
&& let Some(anchor) = anchor {
|
||||
self.motion(Motion::Jump { anchor, line }, window, cx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,15 +221,14 @@ impl Vim {
|
|||
if actions.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if globals.replayer.is_none() {
|
||||
if let Some(recording_register) = globals.recording_register {
|
||||
if globals.replayer.is_none()
|
||||
&& let Some(recording_register) = globals.recording_register {
|
||||
globals
|
||||
.recordings
|
||||
.entry(recording_register)
|
||||
.or_default()
|
||||
.push(ReplayableAction::Action(Repeat.boxed_clone()));
|
||||
}
|
||||
}
|
||||
|
||||
let mut mode = None;
|
||||
let selection = globals.recorded_selection.clone();
|
||||
|
@ -320,11 +319,10 @@ impl Vim {
|
|||
// vim doesn't treat 3a1 as though you literally repeated a1
|
||||
// 3 times, instead it inserts the content thrice at the insert position.
|
||||
if let Some(to_repeat) = repeatable_insert(&actions[0]) {
|
||||
if let Some(ReplayableAction::Action(action)) = actions.last() {
|
||||
if NormalBefore.partial_eq(&**action) {
|
||||
if let Some(ReplayableAction::Action(action)) = actions.last()
|
||||
&& NormalBefore.partial_eq(&**action) {
|
||||
actions.pop();
|
||||
}
|
||||
}
|
||||
|
||||
let mut new_actions = actions.clone();
|
||||
actions[0] = ReplayableAction::Action(to_repeat.boxed_clone());
|
||||
|
|
|
@ -100,11 +100,10 @@ fn cover_or_next<I: Iterator<Item = (Range<usize>, Range<usize>)>>(
|
|||
for (open_range, close_range) in ranges {
|
||||
let start_off = open_range.start;
|
||||
let end_off = close_range.end;
|
||||
if let Some(range_filter) = range_filter {
|
||||
if !range_filter(open_range.clone(), close_range.clone()) {
|
||||
if let Some(range_filter) = range_filter
|
||||
&& !range_filter(open_range.clone(), close_range.clone()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let candidate = CandidateWithRanges {
|
||||
candidate: CandidateRange {
|
||||
start: start_off.to_display_point(map),
|
||||
|
@ -1060,12 +1059,11 @@ fn text_object(
|
|||
.filter_map(|(r, m)| if m == target { Some(r) } else { None })
|
||||
.collect();
|
||||
matches.sort_by_key(|r| r.start);
|
||||
if let Some(buffer_range) = matches.first() {
|
||||
if !buffer_range.is_empty() {
|
||||
if let Some(buffer_range) = matches.first()
|
||||
&& !buffer_range.is_empty() {
|
||||
let range = excerpt.map_range_from_buffer(buffer_range.clone());
|
||||
return Some(range.start.to_display_point(map)..range.end.to_display_point(map));
|
||||
}
|
||||
}
|
||||
let buffer_range = excerpt.map_range_from_buffer(around_range.clone());
|
||||
return Some(buffer_range.start.to_display_point(map)..buffer_range.end.to_display_point(map));
|
||||
}
|
||||
|
@ -1529,8 +1527,8 @@ fn surrounding_markers(
|
|||
Some((ch, _)) => ch,
|
||||
_ => '\0',
|
||||
};
|
||||
if let Some((ch, range)) = movement::chars_after(map, point).next() {
|
||||
if ch == open_marker && before_ch != '\\' {
|
||||
if let Some((ch, range)) = movement::chars_after(map, point).next()
|
||||
&& ch == open_marker && before_ch != '\\' {
|
||||
if open_marker == close_marker {
|
||||
let mut total = 0;
|
||||
for ((ch, _), (before_ch, _)) in movement::chars_before(map, point).tuple_windows()
|
||||
|
@ -1549,7 +1547,6 @@ fn surrounding_markers(
|
|||
opening = Some(range)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if opening.is_none() {
|
||||
let mut chars_before = movement::chars_before(map, point).peekable();
|
||||
|
@ -1558,11 +1555,10 @@ fn surrounding_markers(
|
|||
break;
|
||||
}
|
||||
|
||||
if let Some((before_ch, _)) = chars_before.peek() {
|
||||
if *before_ch == '\\' {
|
||||
if let Some((before_ch, _)) = chars_before.peek()
|
||||
&& *before_ch == '\\' {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ch == open_marker {
|
||||
if matched_closes == 0 {
|
||||
|
|
|
@ -412,8 +412,8 @@ impl MarksState {
|
|||
let mut to_write = HashMap::default();
|
||||
|
||||
for (key, value) in &new_points {
|
||||
if self.is_global_mark(key) {
|
||||
if self.global_marks.get(key) != Some(&MarkLocation::Path(path.clone())) {
|
||||
if self.is_global_mark(key)
|
||||
&& self.global_marks.get(key) != Some(&MarkLocation::Path(path.clone())) {
|
||||
if let Some(workspace_id) = self.workspace_id(cx) {
|
||||
let path = path.clone();
|
||||
let key = key.clone();
|
||||
|
@ -426,7 +426,6 @@ impl MarksState {
|
|||
self.global_marks
|
||||
.insert(key.clone(), MarkLocation::Path(path.clone()));
|
||||
}
|
||||
}
|
||||
if old_points.and_then(|o| o.get(key)) != Some(value) {
|
||||
to_write.insert(key.clone(), value.clone());
|
||||
}
|
||||
|
@ -456,8 +455,8 @@ impl MarksState {
|
|||
buffer: &Entity<Buffer>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if let MarkLocation::Buffer(entity_id) = old_path {
|
||||
if let Some(old_marks) = self.multibuffer_marks.remove(&entity_id) {
|
||||
if let MarkLocation::Buffer(entity_id) = old_path
|
||||
&& let Some(old_marks) = self.multibuffer_marks.remove(&entity_id) {
|
||||
let buffer_marks = old_marks
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into_iter().map(|anchor| anchor.text_anchor).collect()))
|
||||
|
@ -465,7 +464,6 @@ impl MarksState {
|
|||
self.buffer_marks
|
||||
.insert(buffer.read(cx).remote_id(), buffer_marks);
|
||||
}
|
||||
}
|
||||
self.watch_buffer(MarkLocation::Path(new_path.clone()), buffer, cx);
|
||||
self.serialize_buffer_marks(new_path, buffer, cx);
|
||||
}
|
||||
|
@ -512,11 +510,9 @@ impl MarksState {
|
|||
.watched_buffers
|
||||
.get(&buffer_id.clone())
|
||||
.map(|(path, _, _)| path.clone())
|
||||
{
|
||||
if let Some(new_path) = this.path_for_buffer(&buffer, cx) {
|
||||
&& let Some(new_path) = this.path_for_buffer(&buffer, cx) {
|
||||
this.rename_buffer(old_path, new_path, &buffer, cx)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
|
@ -897,14 +893,13 @@ impl VimGlobals {
|
|||
self.stop_recording_after_next_action = false;
|
||||
}
|
||||
}
|
||||
if self.replayer.is_none() {
|
||||
if let Some(recording_register) = self.recording_register {
|
||||
if self.replayer.is_none()
|
||||
&& let Some(recording_register) = self.recording_register {
|
||||
self.recordings
|
||||
.entry(recording_register)
|
||||
.or_default()
|
||||
.push(ReplayableAction::Action(action));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn observe_insertion(&mut self, text: &Arc<str>, range_to_replace: Option<Range<isize>>) {
|
||||
|
@ -1330,11 +1325,10 @@ impl MarksMatchInfo {
|
|||
let mut offset = 0;
|
||||
for chunk in chunks {
|
||||
line.push_str(chunk.text);
|
||||
if let Some(highlight_style) = chunk.syntax_highlight_id {
|
||||
if let Some(highlight) = highlight_style.style(cx.theme().syntax()) {
|
||||
if let Some(highlight_style) = chunk.syntax_highlight_id
|
||||
&& let Some(highlight) = highlight_style.style(cx.theme().syntax()) {
|
||||
highlights.push((offset..offset + chunk.text.len(), highlight))
|
||||
}
|
||||
}
|
||||
offset += chunk.text.len();
|
||||
}
|
||||
MarksMatchInfo::Content { line, highlights }
|
||||
|
|
|
@ -174,13 +174,11 @@ impl Vim {
|
|||
if ch.to_string() == pair.start {
|
||||
let start = offset;
|
||||
let mut end = start + 1;
|
||||
if surround {
|
||||
if let Some((next_ch, _)) = chars_and_offset.peek() {
|
||||
if next_ch.eq(&' ') {
|
||||
if surround
|
||||
&& let Some((next_ch, _)) = chars_and_offset.peek()
|
||||
&& next_ch.eq(&' ') {
|
||||
end += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
edits.push((start..end, ""));
|
||||
anchors.push(start..start);
|
||||
break;
|
||||
|
@ -193,13 +191,11 @@ impl Vim {
|
|||
if ch.to_string() == pair.end {
|
||||
let mut start = offset;
|
||||
let end = start + 1;
|
||||
if surround {
|
||||
if let Some((next_ch, _)) = reverse_chars_and_offsets.peek() {
|
||||
if next_ch.eq(&' ') {
|
||||
if surround
|
||||
&& let Some((next_ch, _)) = reverse_chars_and_offsets.peek()
|
||||
&& next_ch.eq(&' ') {
|
||||
start -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
edits.push((start..end, ""));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -217,11 +217,10 @@ impl NeovimConnection {
|
|||
.expect("Could not set nvim cursor position");
|
||||
}
|
||||
|
||||
if let Some(NeovimData::Get { mode, state }) = self.data.back() {
|
||||
if *mode == Mode::Normal && *state == marked_text {
|
||||
if let Some(NeovimData::Get { mode, state }) = self.data.back()
|
||||
&& *mode == Mode::Normal && *state == marked_text {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.data.push_back(NeovimData::Put {
|
||||
state: marked_text.to_string(),
|
||||
})
|
||||
|
|
|
@ -788,11 +788,10 @@ impl Vim {
|
|||
editor.selections.line_mode = false;
|
||||
editor.unregister_addon::<VimAddon>();
|
||||
editor.set_relative_line_number(None, cx);
|
||||
if let Some(vim) = Vim::globals(cx).focused_vim() {
|
||||
if vim.entity_id() == cx.entity().entity_id() {
|
||||
if let Some(vim) = Vim::globals(cx).focused_vim()
|
||||
&& vim.entity_id() == cx.entity().entity_id() {
|
||||
Vim::globals(cx).focused_vim = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Register an action on the editor.
|
||||
|
@ -833,11 +832,10 @@ impl Vim {
|
|||
if self.exit_temporary_mode {
|
||||
self.exit_temporary_mode = false;
|
||||
// Don't switch to insert mode if the action is temporary_normal.
|
||||
if let Some(action) = keystroke_event.action.as_ref() {
|
||||
if action.as_any().downcast_ref::<TemporaryNormal>().is_some() {
|
||||
if let Some(action) = keystroke_event.action.as_ref()
|
||||
&& action.as_any().downcast_ref::<TemporaryNormal>().is_some() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.switch_mode(Mode::Insert, false, window, cx)
|
||||
}
|
||||
if let Some(action) = keystroke_event.action.as_ref() {
|
||||
|
@ -1006,11 +1004,10 @@ impl Vim {
|
|||
Some((point, goal))
|
||||
})
|
||||
}
|
||||
if last_mode == Mode::Insert || last_mode == Mode::Replace {
|
||||
if let Some(prior_tx) = prior_tx {
|
||||
if (last_mode == Mode::Insert || last_mode == Mode::Replace)
|
||||
&& let Some(prior_tx) = prior_tx {
|
||||
editor.group_until_transaction(prior_tx, cx)
|
||||
}
|
||||
}
|
||||
|
||||
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
|
||||
// we cheat with visual block mode and use multiple cursors.
|
||||
|
@ -1031,15 +1028,14 @@ impl Vim {
|
|||
}
|
||||
|
||||
let snapshot = s.display_map();
|
||||
if let Some(pending) = s.pending.as_mut() {
|
||||
if pending.selection.reversed && mode.is_visual() && !last_mode.is_visual() {
|
||||
if let Some(pending) = s.pending.as_mut()
|
||||
&& pending.selection.reversed && mode.is_visual() && !last_mode.is_visual() {
|
||||
let mut end = pending.selection.end.to_point(&snapshot.buffer_snapshot);
|
||||
end = snapshot
|
||||
.buffer_snapshot
|
||||
.clip_point(end + Point::new(0, 1), Bias::Right);
|
||||
pending.selection.end = snapshot.buffer_snapshot.anchor_before(end);
|
||||
}
|
||||
}
|
||||
|
||||
s.move_with(|map, selection| {
|
||||
if last_mode.is_visual() && !mode.is_visual() {
|
||||
|
@ -1536,13 +1532,12 @@ impl Vim {
|
|||
if self.mode == Mode::Insert && self.current_tx.is_some() {
|
||||
if self.current_anchor.is_none() {
|
||||
self.current_anchor = Some(newest);
|
||||
} else if self.current_anchor.as_ref().unwrap() != &newest {
|
||||
if let Some(tx_id) = self.current_tx.take() {
|
||||
} else if self.current_anchor.as_ref().unwrap() != &newest
|
||||
&& let Some(tx_id) = self.current_tx.take() {
|
||||
self.update_editor(cx, |_, editor, cx| {
|
||||
editor.group_until_transaction(tx_id, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if self.mode == Mode::Normal && newest.start != newest.end {
|
||||
if matches!(newest.goal, SelectionGoal::HorizontalRange { .. }) {
|
||||
self.switch_mode(Mode::VisualBlock, false, window, cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue