Author Topic: Excessive indentation when copy/pasting  (Read 128 times)

timur

  • Senior Community Member
  • Posts: 197
  • Hero Points: 3
Excessive indentation when copy/pasting
« on: July 14, 2022, 09:51:17 pm »
I've had this problem for a few months now, and I can't figure out what's causing it.  I'm using v23 on Linux.

Take this code as an example:
Code: [Select]
if (fwimage) {
} else {
len = ALIGN(fw->len, PAGE_SIZE);

fw->img = vmalloc(len);
if (!fw->img) {
printk(KERN_ERR "failed to vmalloc\n");
return -EINVAL;
}

memcpy(fw->img, src, fw->len);
}

I want to copy/paste the else-block into underneath the if-statement.  So I select lines 3-11, put the cursor on line 2, and hit paste.  This is what I get:
Code: [Select]
if (fwimage) {
len = ALIGN(fw->len, PAGE_SIZE);

fw->img = vmalloc(len);
if (!fw->img) {
printk(KERN_ERR "failed to vmalloc\n");
return -EINVAL;
}

memcpy(fw->img, src, fw->len);
} else {
len = ALIGN(fw->len, PAGE_SIZE);

fw->img = vmalloc(len);
if (!fw->img) {
printk(KERN_ERR "failed to vmalloc\n");
return -EINVAL;
}

memcpy(fw->img, src, fw->len);
}

Why is my code indented so much?  Even weirder, is if I press Ctrl-Z now, it's fixed:
Code: [Select]
if (fwimage) {
len = ALIGN(fw->len, PAGE_SIZE);

fw->img = vmalloc(len);
if (!fw->img) {
printk(KERN_ERR "failed to vmalloc\n");
return -EINVAL;
}

memcpy(fw->img, src, fw->len);
} else {
len = ALIGN(fw->len, PAGE_SIZE);

fw->img = vmalloc(len);
if (!fw->img) {
printk(KERN_ERR "failed to vmalloc\n");
return -EINVAL;
}

memcpy(fw->img, src, fw->len);
}

How do I fix this?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1689
  • Hero Points: 142
Re: Excessive indentation when copy/pasting
« Reply #1 on: July 15, 2022, 03:51:48 pm »
That does sound like one of the beautify on paste bugs we ran into back then.  When a code snippet is beautified for an edit like a paste, it puts in an extra undo, so you can undo just the beautify part.  So that's why the Ctrl-Z fixes the indent for you. If you go to the General options page for C++, and uncheck the setting for beautify on paste, it shouldn't do it anymore.

If you already have the most up to date hotfixes for v23, I don't think there's anything else you can apply.

timur

  • Senior Community Member
  • Posts: 197
  • Hero Points: 3
Re: Excessive indentation when copy/pasting
« Reply #2 on: July 15, 2022, 03:59:28 pm »
That fixed it, thanks.