@@ -18,7 +18,8 @@ use helix_core::{
1818 movement::{self, Direction},
1919 object, pos_at_coords,
2020 regex::{self, Regex, RegexBuilder},
21− search, selection, shellwords, surround, textobject,
21+ search::{self, CharMatcher},
22+ selection, shellwords, surround, textobject,
2223 tree_sitter::Node,
2324 unicode::width::UnicodeWidthChar,
2425 LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril,
@@ -1053,15 +1054,15 @@ where
10531054//
10541055
10551056#[inline]
1056−fn find_char_impl<F>(
1057+fn find_char_impl<F, M: CharMatcher + Clone + Copy>(
10571058 editor: &mut Editor,
10581059 search_fn: &F,
10591060 inclusive: bool,
10601061 extend: bool,
1061− ch: char,
1062+ char_matcher: M,
10621063 count: usize,
10631064) where
1064− F: Fn(RopeSlice, char, usize, usize, bool) -> Option<usize> + 'static,
1065+ F: Fn(RopeSlice, M, usize, usize, bool) -> Option<usize> + 'static,
10651066{
10661067 let (view, doc) = current!(editor);
10671068 let text = doc.text().slice(..);
@@ -1076,7 +1077,7 @@ fn find_char_impl<F>(
10761077 range.head
10771078 };
10781079
1079− search_fn(text, ch, search_start_pos, count, inclusive).map_or(range, |pos| {
1080+ search_fn(text, char_matcher, search_start_pos, count, inclusive).map_or(range, |pos| {
10801081 if extend {
10811082 range.put_cursor(text, pos, true)
10821083 } else {
@@ -4327,8 +4328,39 @@ fn decrement(cx: &mut Context) {
43274328 increment_impl(cx, -(cx.count() as i64));
43284329}
43294330
4331+/// This function differs from find_next_char_impl in that it stops searching at the newline, but also
4332+/// starts searching at the current character, instead of the next.
4333+/// It does not want to start at the next character because this function is used for incrementing
4334+/// number and we don't want to move forward if we're already on a digit.
4335+fn find_next_char_until_newline<M: CharMatcher>(
4336+ text: RopeSlice,
4337+ char_matcher: M,
4338+ pos: usize,
4339+ _count: usize,
4340+ _inclusive: bool,
4341+) -> Option<usize> {
4342+ // Since we send the current line to find_nth_next instead of the whole text, we need to adjust
4343+ // the position we send to this function so that it's relative to that line and its returned
4344+ // position since it's expected this function returns a global position.
4345+ let line_index = text.char_to_line(pos);
4346+ let pos_delta = text.line_to_char(line_index);
4347+ let pos = pos - pos_delta;
4348+ search::find_nth_next(text.line(line_index), char_matcher, pos, 1).map(|pos| pos + pos_delta)
4349+}
4350+
43304351/// Decrement object under cursor by `amount`.
43314352fn increment_impl(cx: &mut Context, amount: i64) {
4353+ // TODO: when incrementing or decrementing a number that gets a new digit or lose one, the
4354+ // selection is updated improperly.
4355+ find_char_impl(
4356+ cx.editor,
4357+ &find_next_char_until_newline,
4358+ true,
4359+ true,
4360+ char::is_ascii_digit,
4361+ 1,
4362+ );
4363+
43324364 let (view, doc) = current!(cx.editor);
43334365 let selection = doc.selection(view.id);
43344366 let text = doc.text().slice(..);