mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-08-17 20:10:26 +03:00
Use range positions to determine insert_newline motion (#9448)
* use anchor and head positions to determine motion * use range cursor to decide extending or shifting * add condition to cursor moving back on normal
This commit is contained in:
parent
87a720c3a1
commit
cf4492174d
@ -3651,7 +3651,7 @@ pub fn insert_newline(cx: &mut Context) {
|
|||||||
(pos, pos, local_offs)
|
(pos, pos, local_offs)
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_range = if doc.restore_cursor {
|
let new_range = if range.cursor(text) > range.anchor {
|
||||||
// when appending, extend the range by local_offs
|
// when appending, extend the range by local_offs
|
||||||
Range::new(
|
Range::new(
|
||||||
range.anchor + global_offs,
|
range.anchor + global_offs,
|
||||||
|
@ -1990,10 +1990,12 @@ pub fn enter_normal_mode(&mut self) {
|
|||||||
if doc.restore_cursor {
|
if doc.restore_cursor {
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let selection = doc.selection(view.id).clone().transform(|range| {
|
let selection = doc.selection(view.id).clone().transform(|range| {
|
||||||
Range::new(
|
let mut head = range.to();
|
||||||
range.from(),
|
if range.head > range.anchor {
|
||||||
graphemes::prev_grapheme_boundary(text, range.to()),
|
head = graphemes::prev_grapheme_boundary(text, head);
|
||||||
)
|
}
|
||||||
|
|
||||||
|
Range::new(range.from(), head)
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
|
Loading…
Reference in New Issue
Block a user