@@ -3511,6 +3511,8 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
3511
3511
let text = doc. text ( ) ;
3512
3512
let selection = doc. selection ( view. id ) ;
3513
3513
3514
+ let mut ranges = SmallVec :: with_capacity ( selection. len ( ) ) ;
3515
+
3514
3516
let transaction = Transaction :: change_by_selection ( text, selection, |range| {
3515
3517
let pos = match ( action, linewise) {
3516
3518
// paste linewise before
@@ -3527,8 +3529,21 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
3527
3529
// paste at cursor
3528
3530
( Paste :: Cursor , _) => range. cursor ( text. slice ( ..) ) ,
3529
3531
} ;
3530
- ( pos, pos, values. next ( ) )
3532
+
3533
+ let value = values. next ( ) ;
3534
+
3535
+ let value_len = value
3536
+ . as_ref ( )
3537
+ . map ( |content| content. chars ( ) . count ( ) )
3538
+ . unwrap_or_default ( ) ;
3539
+
3540
+ ranges. push ( Range :: new ( pos, pos + value_len) ) ;
3541
+
3542
+ ( pos, pos, value)
3531
3543
} ) ;
3544
+
3545
+ let transaction = transaction. with_selection ( Selection :: new ( ranges, selection. primary_index ( ) ) ) ;
3546
+
3532
3547
apply_transaction ( & transaction, doc, view) ;
3533
3548
}
3534
3549
@@ -4782,6 +4797,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4782
4797
let selection = doc. selection ( view. id ) ;
4783
4798
4784
4799
let mut changes = Vec :: with_capacity ( selection. len ( ) ) ;
4800
+ let mut ranges = SmallVec :: with_capacity ( selection. len ( ) ) ;
4785
4801
let text = doc. text ( ) . slice ( ..) ;
4786
4802
4787
4803
for range in selection. ranges ( ) {
@@ -4805,11 +4821,13 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4805
4821
ShellBehavior :: Append => ( range. to ( ) , range. to ( ) ) ,
4806
4822
_ => ( range. from ( ) , range. from ( ) ) ,
4807
4823
} ;
4824
+ ranges. push ( Range :: new ( to, to + output. chars ( ) . count ( ) ) ) ;
4808
4825
changes. push ( ( from, to, Some ( output) ) ) ;
4809
4826
}
4810
4827
4811
4828
if behavior != & ShellBehavior :: Ignore {
4812
- let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) ) ;
4829
+ let transaction = Transaction :: change ( doc. text ( ) , changes. into_iter ( ) )
4830
+ . with_selection ( Selection :: new ( ranges, selection. primary_index ( ) ) ) ;
4813
4831
apply_transaction ( & transaction, doc, view) ;
4814
4832
doc. append_changes_to_history ( view. id ) ;
4815
4833
}
0 commit comments