Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Andriamanitra opened this issue Oct 30, 2023 · 2 comments · Fixed by #3002
Closed

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

Andriamanitra opened this issue Oct 30, 2023 · 2 comments · Fixed by #3002

Comments

@Andriamanitra
Copy link
Contributor

Andriamanitra commented Oct 30, 2023

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

JoeKar pushed a commit that referenced this issue Mar 13, 2024
* smarterpaste(?)

* make it more readable

* fix edge cases

* fix paste starting with a single space

* fix single line paste
@randomcoder67
Copy link

The first case seems to be fixed now, but the second case still happens:

Coping this text, with the first selected character as f:

	for i {
		print(i)
	}

And pasting when X != 0 will result in this:

	// existing code
	for i {
			print(i)
		}

@JoeKar
Copy link
Collaborator

JoeKar commented Dec 29, 2024

We discussed about it in #3002 (comment).
There was no simple and smart solution so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants