Make vim visual block work better
This commit is contained in:
@@ -509,11 +509,12 @@ impl DisplaySnapshot {
|
||||
pub fn highlighted_chunks<'a>(
|
||||
&'a self,
|
||||
display_rows: Range<u32>,
|
||||
language_aware: bool,
|
||||
style: &'a EditorStyle,
|
||||
) -> impl Iterator<Item = HighlightedChunk<'a>> {
|
||||
self.chunks(
|
||||
display_rows,
|
||||
true,
|
||||
language_aware,
|
||||
Some(style.theme.hint),
|
||||
Some(style.theme.suggestion),
|
||||
)
|
||||
@@ -562,7 +563,7 @@ impl DisplaySnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
fn layout_line_for_row(
|
||||
pub fn lay_out_line_for_row(
|
||||
&self,
|
||||
display_row: u32,
|
||||
TextLayoutDetails {
|
||||
@@ -575,7 +576,7 @@ impl DisplaySnapshot {
|
||||
let mut line = String::new();
|
||||
|
||||
let range = display_row..display_row + 1;
|
||||
for chunk in self.highlighted_chunks(range, editor_style) {
|
||||
for chunk in self.highlighted_chunks(range, false, editor_style) {
|
||||
line.push_str(chunk.chunk);
|
||||
|
||||
let text_style = if let Some(style) = chunk.style {
|
||||
@@ -607,7 +608,7 @@ impl DisplaySnapshot {
|
||||
display_point: DisplayPoint,
|
||||
text_layout_details: &TextLayoutDetails,
|
||||
) -> f32 {
|
||||
let layout_line = self.layout_line_for_row(display_point.row(), text_layout_details);
|
||||
let layout_line = self.lay_out_line_for_row(display_point.row(), text_layout_details);
|
||||
layout_line.x_for_index(display_point.column() as usize)
|
||||
}
|
||||
|
||||
@@ -617,7 +618,7 @@ impl DisplaySnapshot {
|
||||
x_coordinate: f32,
|
||||
text_layout_details: &TextLayoutDetails,
|
||||
) -> u32 {
|
||||
let layout_line = self.layout_line_for_row(display_row, text_layout_details);
|
||||
let layout_line = self.lay_out_line_for_row(display_row, text_layout_details);
|
||||
layout_line.closest_index_for_x(x_coordinate) as u32
|
||||
}
|
||||
|
||||
|
||||
@@ -1583,7 +1583,7 @@ impl EditorElement {
|
||||
.collect()
|
||||
} else {
|
||||
let style = &self.style;
|
||||
let chunks = snapshot.highlighted_chunks(rows.clone(), style);
|
||||
let chunks = snapshot.highlighted_chunks(rows.clone(), true, style);
|
||||
|
||||
LineWithInvisibles::from_chunks(
|
||||
chunks,
|
||||
|
||||
@@ -107,7 +107,6 @@ pub fn up_by_rows(
|
||||
SelectionGoal::HorizontalPosition(x) => x,
|
||||
SelectionGoal::WrappedHorizontalPosition((_, x)) => x,
|
||||
SelectionGoal::HorizontalRange { end, .. } => end,
|
||||
SelectionGoal::WrappedHorizontalRange { end: (_, end), .. } => end,
|
||||
_ => map.x_for_point(start, text_layout_details),
|
||||
};
|
||||
|
||||
@@ -144,7 +143,6 @@ pub fn down_by_rows(
|
||||
SelectionGoal::HorizontalPosition(x) => x,
|
||||
SelectionGoal::WrappedHorizontalPosition((_, x)) => x,
|
||||
SelectionGoal::HorizontalRange { end, .. } => end,
|
||||
SelectionGoal::WrappedHorizontalRange { end: (_, end), .. } => end,
|
||||
_ => map.x_for_point(start, text_layout_details),
|
||||
};
|
||||
|
||||
|
||||
@@ -313,10 +313,12 @@ impl SelectionsCollection {
|
||||
let is_empty = positions.start == positions.end;
|
||||
let line_len = display_map.line_len(row);
|
||||
|
||||
let start_col = display_map.column_for_x(row, positions.start, text_layout_details);
|
||||
let layed_out_line = display_map.lay_out_line_for_row(row, &text_layout_details);
|
||||
|
||||
let start_col = layed_out_line.closest_index_for_x(positions.start) as u32;
|
||||
if start_col < line_len || (is_empty && start_col == line_len) {
|
||||
let start = DisplayPoint::new(row, start_col);
|
||||
let end_col = display_map.column_for_x(row, positions.end, text_layout_details);
|
||||
let end_col = layed_out_line.closest_index_for_x(positions.end) as u32;
|
||||
let end = DisplayPoint::new(row, end_col);
|
||||
|
||||
Some(Selection {
|
||||
|
||||
Reference in New Issue
Block a user