multi_buffer: Typed MultiBufferOffset (#42707)
This PR introduces a new `MultiBufferOffset` new type wrapping size. The goal of this is to make it clear at the type level when we are interacting with offsets of a multi buffer versus offsets of a language / text buffer. This improves readability of things quite a bit by making it clear what kind of offsets one is working with while also reducing accidental bugs by using the wrong kin of offset for the wrong API. This PR also uncovered two minor bugs due to that. Does not yet introduce the MultiBufferPoint equivalent, that is for a follow up PR. Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use collections::HashMap;
|
||||
use editor::{
|
||||
Bias, DisplayPoint, Editor, SelectionEffects,
|
||||
Bias, DisplayPoint, Editor, MultiBufferOffset, SelectionEffects,
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
movement,
|
||||
};
|
||||
@@ -778,7 +778,7 @@ impl Vim {
|
||||
{
|
||||
let range = row_range.start.to_offset(&display_map, Bias::Right)
|
||||
..row_range.end.to_offset(&display_map, Bias::Right);
|
||||
let text = text.repeat(range.len());
|
||||
let text = text.repeat(range.end - range.start);
|
||||
edits.push((range, text));
|
||||
}
|
||||
}
|
||||
@@ -844,8 +844,8 @@ impl Vim {
|
||||
return;
|
||||
};
|
||||
let vim_is_normal = self.mode == Mode::Normal;
|
||||
let mut start_selection = 0usize;
|
||||
let mut end_selection = 0usize;
|
||||
let mut start_selection = MultiBufferOffset(0);
|
||||
let mut end_selection = MultiBufferOffset(0);
|
||||
|
||||
self.update_editor(cx, |_, editor, _| {
|
||||
editor.set_collapse_matches(false);
|
||||
@@ -868,7 +868,7 @@ impl Vim {
|
||||
self.update_editor(cx, |_, editor, cx| {
|
||||
let latest = editor
|
||||
.selections
|
||||
.newest::<usize>(&editor.display_snapshot(cx));
|
||||
.newest::<MultiBufferOffset>(&editor.display_snapshot(cx));
|
||||
start_selection = latest.start;
|
||||
end_selection = latest.end;
|
||||
});
|
||||
@@ -891,7 +891,7 @@ impl Vim {
|
||||
self.update_editor(cx, |_, editor, cx| {
|
||||
let latest = editor
|
||||
.selections
|
||||
.newest::<usize>(&editor.display_snapshot(cx));
|
||||
.newest::<MultiBufferOffset>(&editor.display_snapshot(cx));
|
||||
if vim_is_normal {
|
||||
start_selection = latest.start;
|
||||
end_selection = latest.end;
|
||||
|
||||
Reference in New Issue
Block a user