Skip to content

Smartpaste isn't smart when pasting indented blocks with cursor.X > 0 #3001

@Andriamanitra

Description

@Andriamanitra

Description of the problem or steps to reproduce

When pasting indented code block such as

    if (1) {
        printf("Hello world\n");
    }

with setlocal smartpaste on micro formats it like this:

    // (paste happens at the same indent level as this comment)
    // if you selected the leading whitespace on the first line:
        if (1) {
        printf("Hello world\n");
    }
    // and if you didn't select the leading whitespace on the first line:
    if (1) {
            printf("Hello world\n");
        }

Note that the problem only happens when cursor is not at X=0 (no indent).

Asciinema demonstration

Current behavior on the left pane, my attempt at fixing some of it on the right:
https://asciinema.org/a/617870 (problems start at 00:30)
The version used on the recording is not the latest but I checked that the behavior hasn't changed since 2.0.12

test file used on the recording
def f():
    if x:
        print("    hello")

# Happy cases:
# 1) Paste block with no indent when cursor.X > 0

# 2) Paste indented block when cursor.X = 0

# 3) Single line with leading spaces


def f() {
    if x {
        ABC
    }
}
# Problematic cases:
# 1) Paste indented block when cursor.X > 0

# 2) Non-matching indentation

# 3) Paste decreasing indentation when cursor.X > 0


# Unsolvable(?) edge cases:
# 1) paste poorly selected (no indent on first line) when cursor.X = 0

# 2) paste poorly selected (no indent on first line) when cursor.X > 0

Version info

Commit hash: d8e9d61
OS: Linux (OpenSUSE Tumbleweed)
Terminal: terminator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions