Skip to content

Commit

Permalink
remove Range.shorten in favor of an inline solution
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Oct 12, 2022
1 parent a8524b6 commit 1f9d56b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
3 changes: 1 addition & 2 deletions helix-core/src/increment/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ impl<'a> IntegerIncrementor<'a> {
};

// If there are trailing underscores, remove them from the range.
// There is a `- 1` here because range ends are exclusive.
while !range.is_empty() && text.char(range.to() - 1) == '_' {
range = range.shorten()
range = Range::new(range.from(), range.to() - 1)
}

let word: String = text
Expand Down
18 changes: 0 additions & 18 deletions helix-core/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,6 @@ impl Range {
}
}

/// Shorten the range by 1 character.
#[must_use]
pub fn shorten(&self) -> Self {
match self.head.cmp(&self.anchor) {
std::cmp::Ordering::Greater => Self {
anchor: self.anchor,
head: self.head - 1,
horiz: None,
},
std::cmp::Ordering::Less => Self {
anchor: self.anchor - 1,
head: self.head,
horiz: None,
},
std::cmp::Ordering::Equal => *self,
}
}

/// Returns a range that encompasses both input ranges.
///
/// This is like `extend()`, but tries to negotiate the
Expand Down
5 changes: 3 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4867,8 +4867,9 @@ fn increment_impl(cx: &mut Context, amount: i64) {
}

if !changes.is_empty() {
let new_selection_primary =
selection.primary_index().min(new_selection_ranges.len() - 1);
let new_selection_primary = selection
.primary_index()
.min(new_selection_ranges.len() - 1);
let new_selection = Selection::new(new_selection_ranges, new_selection_primary);

let transaction = Transaction::change(doc.text(), changes.into_iter());
Expand Down

0 comments on commit 1f9d56b

Please sign in to comment.