From ec6e575a408372400b7789b90cdf6ac271f51182 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 11 Feb 2023 18:45:30 +0100 Subject: Correctly handle multiple cursors with LSP snippets --- helix-core/src/selection.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'helix-core') diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 0ac2c680..0db7634c 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -578,6 +578,16 @@ impl Selection { self.normalize() } + /// Takes a closure and maps each `Range` over the closure to multiple `Range`s. + pub fn transform_iter(mut self, f: F) -> Self + where + F: FnMut(Range) -> I, + I: Iterator, + { + self.ranges = self.ranges.into_iter().flat_map(f).collect(); + self.normalize() + } + // Ensures the selection adheres to the following invariants: // 1. All ranges are grapheme aligned. // 2. All ranges are at least 1 character wide, unless at the -- cgit v1.2.3-70-g09d2