Fix up test_vim_visual_selections
This commit is contained in:
parent
9695ea1017
commit
ee695bbb34
1 changed files with 139 additions and 123 deletions
|
@ -3310,137 +3310,153 @@ mod tests {
|
||||||
assert_eq!(relative_rows[&2], 3);
|
assert_eq!(relative_rows[&2], 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[gpui::test]
|
#[gpui::test]
|
||||||
// async fn test_vim_visual_selections(cx: &mut TestAppContext) {
|
async fn test_vim_visual_selections(cx: &mut TestAppContext) {
|
||||||
// init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
|
|
||||||
// let editor = cx
|
let window = cx.add_window(|cx| {
|
||||||
// .add_window(|cx| {
|
let buffer = MultiBuffer::build_simple(&(sample_text(6, 6, 'a') + "\n"), cx);
|
||||||
// let buffer = MultiBuffer::build_simple(&(sample_text(6, 6, 'a') + "\n"), cx);
|
Editor::new(EditorMode::Full, buffer, None, cx)
|
||||||
// Editor::new(EditorMode::Full, buffer, None, None, cx)
|
});
|
||||||
// })
|
let editor = window.root(cx).unwrap();
|
||||||
// .root(cx);
|
let style = cx.update(|cx| editor.read(cx).style().unwrap().clone());
|
||||||
// let mut element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));
|
let mut element = EditorElement::new(&editor, style);
|
||||||
// let (_, state) = editor.update(cx, |editor, cx| {
|
|
||||||
// editor.cursor_shape = CursorShape::Block;
|
|
||||||
// editor.change_selections(None, cx, |s| {
|
|
||||||
// s.select_ranges([
|
|
||||||
// Point::new(0, 0)..Point::new(1, 0),
|
|
||||||
// Point::new(3, 2)..Point::new(3, 3),
|
|
||||||
// Point::new(5, 6)..Point::new(6, 0),
|
|
||||||
// ]);
|
|
||||||
// });
|
|
||||||
// element.layout(
|
|
||||||
// SizeConstraint::new(point(500., 500.), point(500., 500.)),
|
|
||||||
// editor,
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// });
|
|
||||||
// assert_eq!(state.selections.len(), 1);
|
|
||||||
// let local_selections = &state.selections[0].1;
|
|
||||||
// assert_eq!(local_selections.len(), 3);
|
|
||||||
// // moves cursor back one line
|
|
||||||
// assert_eq!(local_selections[0].head, DisplayPoint::new(0, 6));
|
|
||||||
// assert_eq!(
|
|
||||||
// local_selections[0].range,
|
|
||||||
// DisplayPoint::new(0, 0)..DisplayPoint::new(1, 0)
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // moves cursor back one column
|
window
|
||||||
// assert_eq!(
|
.update(cx, |editor, cx| {
|
||||||
// local_selections[1].range,
|
editor.cursor_shape = CursorShape::Block;
|
||||||
// DisplayPoint::new(3, 2)..DisplayPoint::new(3, 3)
|
editor.change_selections(None, cx, |s| {
|
||||||
// );
|
s.select_ranges([
|
||||||
// assert_eq!(local_selections[1].head, DisplayPoint::new(3, 2));
|
Point::new(0, 0)..Point::new(1, 0),
|
||||||
|
Point::new(3, 2)..Point::new(3, 3),
|
||||||
|
Point::new(5, 6)..Point::new(6, 0),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let state = cx
|
||||||
|
.update_window(window.into(), |_, cx| {
|
||||||
|
element.compute_layout(
|
||||||
|
Bounds {
|
||||||
|
origin: point(px(500.), px(500.)),
|
||||||
|
size: size(px(500.), px(500.)),
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// // leaves cursor on the max point
|
assert_eq!(state.selections.len(), 1);
|
||||||
// assert_eq!(
|
let local_selections = &state.selections[0].1;
|
||||||
// local_selections[2].range,
|
assert_eq!(local_selections.len(), 3);
|
||||||
// DisplayPoint::new(5, 6)..DisplayPoint::new(6, 0)
|
// moves cursor back one line
|
||||||
// );
|
assert_eq!(local_selections[0].head, DisplayPoint::new(0, 6));
|
||||||
// assert_eq!(local_selections[2].head, DisplayPoint::new(6, 0));
|
assert_eq!(
|
||||||
|
local_selections[0].range,
|
||||||
|
DisplayPoint::new(0, 0)..DisplayPoint::new(1, 0)
|
||||||
|
);
|
||||||
|
|
||||||
// // active lines does not include 1 (even though the range of the selection does)
|
// moves cursor back one column
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// state.active_rows.keys().cloned().collect::<Vec<u32>>(),
|
local_selections[1].range,
|
||||||
// vec![0, 3, 5, 6]
|
DisplayPoint::new(3, 2)..DisplayPoint::new(3, 3)
|
||||||
// );
|
);
|
||||||
|
assert_eq!(local_selections[1].head, DisplayPoint::new(3, 2));
|
||||||
|
|
||||||
// // multi-buffer support
|
// leaves cursor on the max point
|
||||||
// // in DisplayPoint co-ordinates, this is what we're dealing with:
|
assert_eq!(
|
||||||
// // 0: [[file
|
local_selections[2].range,
|
||||||
// // 1: header]]
|
DisplayPoint::new(5, 6)..DisplayPoint::new(6, 0)
|
||||||
// // 2: aaaaaa
|
);
|
||||||
// // 3: bbbbbb
|
assert_eq!(local_selections[2].head, DisplayPoint::new(6, 0));
|
||||||
// // 4: cccccc
|
|
||||||
// // 5:
|
|
||||||
// // 6: ...
|
|
||||||
// // 7: ffffff
|
|
||||||
// // 8: gggggg
|
|
||||||
// // 9: hhhhhh
|
|
||||||
// // 10:
|
|
||||||
// // 11: [[file
|
|
||||||
// // 12: header]]
|
|
||||||
// // 13: bbbbbb
|
|
||||||
// // 14: cccccc
|
|
||||||
// // 15: dddddd
|
|
||||||
// let editor = cx
|
|
||||||
// .add_window(|cx| {
|
|
||||||
// let buffer = MultiBuffer::build_multi(
|
|
||||||
// [
|
|
||||||
// (
|
|
||||||
// &(sample_text(8, 6, 'a') + "\n"),
|
|
||||||
// vec![
|
|
||||||
// Point::new(0, 0)..Point::new(3, 0),
|
|
||||||
// Point::new(4, 0)..Point::new(7, 0),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// (
|
|
||||||
// &(sample_text(8, 6, 'a') + "\n"),
|
|
||||||
// vec![Point::new(1, 0)..Point::new(3, 0)],
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// Editor::new(EditorMode::Full, buffer, None, None, cx)
|
|
||||||
// })
|
|
||||||
// .root(cx);
|
|
||||||
// let mut element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx)));
|
|
||||||
// let (_, state) = editor.update(cx, |editor, cx| {
|
|
||||||
// editor.cursor_shape = CursorShape::Block;
|
|
||||||
// editor.change_selections(None, cx, |s| {
|
|
||||||
// s.select_display_ranges([
|
|
||||||
// DisplayPoint::new(4, 0)..DisplayPoint::new(7, 0),
|
|
||||||
// DisplayPoint::new(10, 0)..DisplayPoint::new(13, 0),
|
|
||||||
// ]);
|
|
||||||
// });
|
|
||||||
// element.layout(
|
|
||||||
// SizeConstraint::new(point(500., 500.), point(500., 500.)),
|
|
||||||
// editor,
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// });
|
|
||||||
|
|
||||||
// assert_eq!(state.selections.len(), 1);
|
// active lines does not include 1 (even though the range of the selection does)
|
||||||
// let local_selections = &state.selections[0].1;
|
assert_eq!(
|
||||||
// assert_eq!(local_selections.len(), 2);
|
state.active_rows.keys().cloned().collect::<Vec<u32>>(),
|
||||||
|
vec![0, 3, 5, 6]
|
||||||
|
);
|
||||||
|
|
||||||
// // moves cursor on excerpt boundary back a line
|
// multi-buffer support
|
||||||
// // and doesn't allow selection to bleed through
|
// in DisplayPoint co-ordinates, this is what we're dealing with:
|
||||||
// assert_eq!(
|
// 0: [[file
|
||||||
// local_selections[0].range,
|
// 1: header]]
|
||||||
// DisplayPoint::new(4, 0)..DisplayPoint::new(6, 0)
|
// 2: aaaaaa
|
||||||
// );
|
// 3: bbbbbb
|
||||||
// assert_eq!(local_selections[0].head, DisplayPoint::new(5, 0));
|
// 4: cccccc
|
||||||
|
// 5:
|
||||||
|
// 6: ...
|
||||||
|
// 7: ffffff
|
||||||
|
// 8: gggggg
|
||||||
|
// 9: hhhhhh
|
||||||
|
// 10:
|
||||||
|
// 11: [[file
|
||||||
|
// 12: header]]
|
||||||
|
// 13: bbbbbb
|
||||||
|
// 14: cccccc
|
||||||
|
// 15: dddddd
|
||||||
|
let window = cx.add_window(|cx| {
|
||||||
|
let buffer = MultiBuffer::build_multi(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
&(sample_text(8, 6, 'a') + "\n"),
|
||||||
|
vec![
|
||||||
|
Point::new(0, 0)..Point::new(3, 0),
|
||||||
|
Point::new(4, 0)..Point::new(7, 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
&(sample_text(8, 6, 'a') + "\n"),
|
||||||
|
vec![Point::new(1, 0)..Point::new(3, 0)],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
Editor::new(EditorMode::Full, buffer, None, cx)
|
||||||
|
});
|
||||||
|
let editor = window.root(cx).unwrap();
|
||||||
|
let style = cx.update(|cx| editor.read(cx).style().unwrap().clone());
|
||||||
|
let mut element = EditorElement::new(&editor, style);
|
||||||
|
let state = window.update(cx, |editor, cx| {
|
||||||
|
editor.cursor_shape = CursorShape::Block;
|
||||||
|
editor.change_selections(None, cx, |s| {
|
||||||
|
s.select_display_ranges([
|
||||||
|
DisplayPoint::new(4, 0)..DisplayPoint::new(7, 0),
|
||||||
|
DisplayPoint::new(10, 0)..DisplayPoint::new(13, 0),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// // moves cursor on buffer boundary back two lines
|
let state = cx
|
||||||
// // and doesn't allow selection to bleed through
|
.update_window(window.into(), |_, cx| {
|
||||||
// assert_eq!(
|
element.compute_layout(
|
||||||
// local_selections[1].range,
|
Bounds {
|
||||||
// DisplayPoint::new(10, 0)..DisplayPoint::new(11, 0)
|
origin: point(px(500.), px(500.)),
|
||||||
// );
|
size: size(px(500.), px(500.)),
|
||||||
// assert_eq!(local_selections[1].head, DisplayPoint::new(10, 0));
|
},
|
||||||
// }
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(state.selections.len(), 1);
|
||||||
|
let local_selections = &state.selections[0].1;
|
||||||
|
assert_eq!(local_selections.len(), 2);
|
||||||
|
|
||||||
|
// moves cursor on excerpt boundary back a line
|
||||||
|
// and doesn't allow selection to bleed through
|
||||||
|
assert_eq!(
|
||||||
|
local_selections[0].range,
|
||||||
|
DisplayPoint::new(4, 0)..DisplayPoint::new(6, 0)
|
||||||
|
);
|
||||||
|
assert_eq!(local_selections[0].head, DisplayPoint::new(5, 0));
|
||||||
|
dbg!("Hi");
|
||||||
|
// moves cursor on buffer boundary back two lines
|
||||||
|
// and doesn't allow selection to bleed through
|
||||||
|
assert_eq!(
|
||||||
|
local_selections[1].range,
|
||||||
|
DisplayPoint::new(10, 0)..DisplayPoint::new(11, 0)
|
||||||
|
);
|
||||||
|
assert_eq!(local_selections[1].head, DisplayPoint::new(10, 0));
|
||||||
|
}
|
||||||
|
|
||||||
// #[gpui::test]
|
// #[gpui::test]
|
||||||
// fn test_layout_with_placeholder_text_and_blocks(cx: &mut TestAppContext) {
|
// fn test_layout_with_placeholder_text_and_blocks(cx: &mut TestAppContext) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue