@@ -277,6 +277,8 @@ impl Command {
277 toggle_comments, "Comment/uncomment selections",
277 toggle_comments, "Comment/uncomment selections",
278 rotate_selections_forward, "Rotate selections forward",
278 rotate_selections_forward, "Rotate selections forward",
279 rotate_selections_backward, "Rotate selections backward",
279 rotate_selections_backward, "Rotate selections backward",
280+ rotate_selection_contents_forward, "Rotate selection contents forward",
281+ rotate_selection_contents_backward, "Rotate selections contents backward",
280 expand_selection, "Expand selection to parent syntax node",
282 expand_selection, "Expand selection to parent syntax node",
281 jump_forward, "Jump forward on jumplist",
283 jump_forward, "Jump forward on jumplist",
282 jump_backward, "Jump backward on jumplist",
284 jump_backward, "Jump backward on jumplist",
@@ -3768,6 +3770,49 @@ fn rotate_selections_backward(cx: &mut Context) {
3768 rotate_selections(cx, Direction::Backward)
3770 rotate_selections(cx, Direction::Backward)
3773+fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
3774+ let count = cx.count;
3775+ let (view, doc) = current!(cx.editor);
3776+ let text = doc.text().slice(..);
3778+ let selection = doc.selection(view.id);
3779+ let mut fragments: Vec<_> = selection
3781+ .map(|fragment| Tendril::from_slice(&fragment))
3785+ .map(|count| count.get())
3786+ .unwrap_or(fragments.len()) // default to rotating everything as one group
3787+ .min(fragments.len());
3789+ for chunk in fragments.chunks_mut(group) {
3790+ // TODO: also modify main index
3792+ Direction::Forward => chunk.rotate_right(1),
3793+ Direction::Backward => chunk.rotate_left(1),
3797+ let transaction = Transaction::change(
3803+ .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
3806+ doc.apply(&transaction, view.id);
3807+ doc.append_changes_to_history(view.id);
3809+fn rotate_selection_contents_forward(cx: &mut Context) {
3810+ rotate_selection_contents(cx, Direction::Forward)
3812+fn rotate_selection_contents_backward(cx: &mut Context) {
3813+ rotate_selection_contents(cx, Direction::Backward)
3771// tree sitter node selection
3816// tree sitter node selection
3773fn expand_selection(cx: &mut Context) {
3818fn expand_selection(cx: &mut Context) {