on master help sign in
Fix extend line behavior.
commit13b0784009cd0c1150ba7fac2bac1465360be6dd authorNathan Vegdahl <cessen@cessen.com> dateMon 19 Jul 2021, 17:44 (5 years ago) parente98d669
1 file changed+14−11
helix-term/src/commands.rs+14−11
helix-term/src/commands.rs+14−11
@@ -1125,17 +1125,17 @@ fn extend_line(cx: &mut Context) {
11251125 let (view, doc) = current!(cx.editor);
11261126
11271127 let text = doc.text();
1128− let pos = doc.selection(view.id).primary().min_width_1(text.slice(..));
1128+ let range = doc.selection(view.id).primary().min_width_1(text.slice(..));
11291129
1130− let line_max = text.len_lines();
1131− let start_line = text.char_to_line(pos.from()).min(line_max);
1132− let end_line = (text.char_to_line(pos.to()) + count).min(line_max);
1130+ let start_line = text.char_to_line(range.from());
1131+ let end_line = (text.char_to_line(range.to().saturating_sub(1).max(range.from())) + count)
1132+ .min(text.len_lines());
11331133
11341134 let start = text.line_to_char(start_line);
11351135 let mut end = text.line_to_char(end_line);
11361136
1137− if pos.from() == start && pos.to() == end {
1138− end = text.line_to_char((end_line + 1).min(line_max));
1137+ if range.from() == start && range.to() == end {
1138+ end = text.line_to_char((end_line + 1).min(text.len_lines()));
11391139 }
11401140
11411141 doc.set_selection(view.id, Selection::single(start, end));
@@ -1148,12 +1148,15 @@ fn extend_to_line_bounds(cx: &mut Context) {
11481148 view.id,
11491149 doc.selection(view.id).clone().transform(|range| {
11501150 let text = doc.text();
1151− let start = text.line_to_char(text.char_to_line(range.from()));
1152− let end = text
1153− .line_to_char(text.char_to_line(range.to()) + 1)
1154− .saturating_sub(1);
11551151
1156− if range.anchor < range.head {
1152+ let start_line = text.char_to_line(range.from());
1153+ let end_line = (text.char_to_line(range.to().saturating_sub(1).max(range.from())) + 1)
1154+ .min(text.len_lines());
1155+
1156+ let start = text.line_to_char(start_line);
1157+ let end = text.line_to_char(end_line);
1158+
1159+ if range.anchor <= range.head {
11571160 Range::new(start, end)
11581161 } else {
11591162 Range::new(end, start)