Sublime Forum

Does anyone else find weird how ctrl+alt+up/down creates new cursors?

#1

Hi:

I find confusing how new carrets are generated when pressing ctrl+alt+up/down several times.

If for some reason:

  1. my carret is positioned at any position other than the beginning of line,
  2. i press ctrl+alt+up/down many times passing through an empty line,
  3. i press ctrl+alt+up/down 3 more times at least

Sublime will generate two carrets:

Example: Initial position.

after pressing ctrl+alt+down:

after pressing ctrl+alt+down again:

after pressing ctrl+alt+down again:

after pressing ctrl+alt+down again twice:

As you see, it will continue creating two carrets per row, which it not really very useful, but confusing.

1 Like

#2

yes, this is a bug

1 Like

#3

This issue is a little bit different to tbe bug report. ST creates a new cursor for each existing cursor.

Some time ago I have created a plugin to do this (and also keep the selection instead of only adding the caret). Select Tools >> Developer >> New Plugin… and paste

import sublime
import sublime_plugin


def _get_point(view, point, forward):
    delta = 1 if forward else -1
    row, col = view.rowcol(point)
    new_row = row + delta
    new_point = view.text_point(new_row, col)
    # if we moved beyond the line end, move to the end of the line
    if view.rowcol(new_point)[0] != new_row:
        new_point = view.text_point(new_row + 1, 0) - 1
    return new_point


class AddSelectionCommand(sublime_plugin.TextCommand):
    def run(self, edit, forward=True, only_caret=True):
        view = self.view
        if not len(view.sel()):
            return
        sel = view.sel()[-1 if forward else 0]
        row, col = view.rowcol(sel.b)
        point_b = _get_point(view, sel.b, forward)
        if only_caret:
            point_a = point_b
        else:
            point_a = _get_point(view, sel.a, forward)
        new_sel = sublime.Region(point_a, point_b)
        view.sel().add(new_sel)

Keybindings:

    {
        "keys": ["ctrl+alt+down"],
        "command": "add_selection",
        "args": {
            "forward": true,
            "only_caret": true
        }
    },
    {
        "keys": ["ctrl+alt+up"],
        "command": "add_selection",
        "args": {
            "forward": false,
            "only_caret": true
        }
    },

0 Likes

#4

I have a plugin that changes the column select behavior: https://packagecontrol.io/packages/Column%20Select
In your example, it will skip over the blank line.

0 Likes