@@ -4903,14 +4903,18 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
4903
4903
apply_transaction ( & transaction, doc, view) ;
4904
4904
}
4905
4905
4906
+ enum IncrementDirection {
4907
+ Increase ,
4908
+ Decrease ,
4909
+ }
4906
4910
/// Increment object under cursor by count.
4907
4911
fn increment ( cx : & mut Context ) {
4908
- increment_impl ( cx, cx . count ( ) as i64 ) ;
4912
+ increment_impl ( cx, IncrementDirection :: Increase ) ;
4909
4913
}
4910
4914
4911
4915
/// Decrement object under cursor by count.
4912
4916
fn decrement ( cx : & mut Context ) {
4913
- increment_impl ( cx, - ( cx . count ( ) as i64 ) ) ;
4917
+ increment_impl ( cx, IncrementDirection :: Decrease ) ;
4914
4918
}
4915
4919
4916
4920
/// This function differs from find_next_char_impl in that it stops searching at the newline, but also
@@ -4934,7 +4938,7 @@ fn find_next_char_until_newline<M: CharMatcher>(
4934
4938
}
4935
4939
4936
4940
/// Decrement object under cursor by `amount`.
4937
- fn increment_impl ( cx : & mut Context , amount : i64 ) {
4941
+ fn increment_impl ( cx : & mut Context , increment_direction : IncrementDirection ) {
4938
4942
// TODO: when incrementing or decrementing a number that gets a new digit or lose one, the
4939
4943
// selection is updated improperly.
4940
4944
find_char_impl (
@@ -4946,6 +4950,17 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4946
4950
1 ,
4947
4951
) ;
4948
4952
4953
+ // Increase by 1 if `IncrementDirection` is `Increase`
4954
+ // Decrease by 1 if `IncrementDirection` is `Decrease`
4955
+ let sign = match increment_direction {
4956
+ IncrementDirection :: Increase => 1 ,
4957
+ IncrementDirection :: Decrease => -1 ,
4958
+ } ;
4959
+ let mut amount = sign * cx. count ( ) as i64 ;
4960
+
4961
+ // If the register is `#` then increase or decrease the `amount` by 1 per element
4962
+ let increase_by = if cx. register == Some ( '#' ) { sign } else { 0 } ;
4963
+
4949
4964
let ( view, doc) = current ! ( cx. editor) ;
4950
4965
let selection = doc. selection ( view. id ) ;
4951
4966
let text = doc. text ( ) . slice ( ..) ;
@@ -4965,6 +4980,8 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4965
4980
4966
4981
let ( range, new_text) = incrementor. increment ( amount) ;
4967
4982
4983
+ amount += increase_by;
4984
+
4968
4985
Some ( ( range. from ( ) , range. to ( ) , Some ( new_text) ) )
4969
4986
} )
4970
4987
. collect ( ) ;
0 commit comments