aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/selection.rs
diff options
context:
space:
mode:
authorMichael Davis2022-07-30 14:20:07 +0000
committerBlaž Hrastnik2022-10-03 14:44:08 +0000
commit274f2ea45979098a96b7a6d94ecc18351826eaea (patch)
tree3b6811253f16b8466060b4737914c4d7fd304693 /helix-core/src/selection.rs
parentf3958aa1fd4518aad0842e3015d991aadce1fd28 (diff)
Use requested direction for new textobject selection range
This changes the behavior of operations like `]f`/`[f` to set the direction of the new range to the direction of the action. The original behavior was to always use the head of the next function. This is inconsistent with the behavior of goto_next_paragraph and makes it impossible to create extend variants of the textobject motions. This causes a behavior change when there are nested functions. The behavior in the parent commit is that repeated uses of `]f` will select every function in the file even if nested. With this commit, functions are skipped. It's notable that it's possible to emulate the original behavior by using the `ensure_selections_forward` (A-:) command between invocations of `]f`.
Diffstat (limited to 'helix-core/src/selection.rs')
-rw-r--r--helix-core/src/selection.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 3463c1d3..1f28ecef 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -122,7 +122,7 @@ impl Range {
}
}
- // flips the direction of the selection
+ /// Flips the direction of the selection
pub fn flip(&self) -> Self {
Self {
anchor: self.head,
@@ -131,6 +131,16 @@ impl Range {
}
}
+ /// Returns the selection if it goes in the direction of `direction`,
+ /// flipping the selection otherwise.
+ pub fn with_direction(self, direction: Direction) -> Self {
+ if self.direction() == direction {
+ self
+ } else {
+ self.flip()
+ }
+ }
+
/// Check two ranges for overlap.
#[must_use]
pub fn overlaps(&self, other: &Self) -> bool {