@@ -4863,14 +4863,18 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
4863
4863
apply_transaction ( & transaction, doc, view) ;
4864
4864
}
4865
4865
4866
+ enum IncrementDirection {
4867
+ Increase ,
4868
+ Decrease ,
4869
+ }
4866
4870
/// Increment object under cursor by count.
4867
4871
fn increment ( cx : & mut Context ) {
4868
- increment_impl ( cx, cx . count ( ) as i64 ) ;
4872
+ increment_impl ( cx, IncrementDirection :: Increase ) ;
4869
4873
}
4870
4874
4871
4875
/// Decrement object under cursor by count.
4872
4876
fn decrement ( cx : & mut Context ) {
4873
- increment_impl ( cx, - ( cx . count ( ) as i64 ) ) ;
4877
+ increment_impl ( cx, IncrementDirection :: Decrease ) ;
4874
4878
}
4875
4879
4876
4880
/// This function differs from find_next_char_impl in that it stops searching at the newline, but also
@@ -4894,7 +4898,7 @@ fn find_next_char_until_newline<M: CharMatcher>(
4894
4898
}
4895
4899
4896
4900
/// Decrement object under cursor by `amount`.
4897
- fn increment_impl ( cx : & mut Context , amount : i64 ) {
4901
+ fn increment_impl ( cx : & mut Context , increment_direction : IncrementDirection ) {
4898
4902
// TODO: when incrementing or decrementing a number that gets a new digit or lose one, the
4899
4903
// selection is updated improperly.
4900
4904
find_char_impl (
@@ -4906,6 +4910,17 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4906
4910
1 ,
4907
4911
) ;
4908
4912
4913
+ // Increase by 1 if `IncrementDirection` is `Increase`
4914
+ // Decrease by 1 if `IncrementDirection` is `Decrease`
4915
+ let sign = match increment_direction {
4916
+ IncrementDirection :: Increase => 1 ,
4917
+ IncrementDirection :: Decrease => -1 ,
4918
+ } ;
4919
+ let mut amount = sign * cx. count ( ) as i64 ;
4920
+
4921
+ // If the register is `#` then increase or decrease the `amount` by 1 per element
4922
+ let increase_by = if cx. register == Some ( '#' ) { sign } else { 0 } ;
4923
+
4909
4924
let ( view, doc) = current ! ( cx. editor) ;
4910
4925
let selection = doc. selection ( view. id ) ;
4911
4926
let text = doc. text ( ) . slice ( ..) ;
@@ -4925,6 +4940,8 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4925
4940
4926
4941
let ( range, new_text) = incrementor. increment ( amount) ;
4927
4942
4943
+ amount += increase_by;
4944
+
4928
4945
Some ( ( range. from ( ) , range. to ( ) , Some ( new_text) ) )
4929
4946
} )
4930
4947
. collect ( ) ;
0 commit comments