atom / atom

:atom: The hackable text editor
https://atom.io
MIT License
60.15k stars 17.4k forks source link

Paste indentation issue with auto-indent off #13505

Open madakk opened 7 years ago

madakk commented 7 years ago

Prerequisites

Description

Paste apparently takes the current indentation into account, even when Auto Indent and Auto Indent On Paste are off. This happens in any grammar, including plain text.

Steps to Reproduce

  1. Type the following:
    a
    b
    c
  2. Copy from (and including) the new-line at the end of the first line, upto the end of the second line. Go to the end of the third line, and paste.

Expected behavior: The result should be:

a
  b
    c
  b

Actual behavior: The result is:

a
  b
    c
      b

Reproduces how often: 100%

Versions

Atom : 1.12.7 Electron: 1.3.13 Chrome : 52.0.2743.82 Node : 6.5.0

apm 1.12.9 npm 3.10.5 node 4.4.5 python git visual studio 2013

Windows 8.1

Additional Information

gif

AndreaGriffiths11 commented 7 years ago

I was able to reproduce on Atom v1.13.0 on Mac OS X 10.12.2.

ajostergaard commented 6 years ago

Same on 1.30.0 x64 with plain text and:

"*":
  editor:
    autoIndent: false
    autoIndentOnPaste: false
    normalizeIndentOnPaste: false

Also, similarly:

a
  b
    c
    d

Copy 'd' to after 'b' and you get:

a
  b
  d
    c
    d

When you were expecting:

a
  b
    d
    c
    d

And the obligatory gif:

atom-indent-bug

Super annoying!

mhulse commented 6 years ago

Related forum post (comes with animated examples):

Copy/paste indent wrong: How to fix?

I run into this issue pretty regularly and always find it annoying as the behavior is different from any other editors I've used. In my humble opinion, it's not intuitive.

Anyway, not sure if it will help, but here's some comparisons:

Atom 1.30.0

atom 1 30 0

TextEdit

textedit

Sublime Text 3.1.1

sublime text 3 1 1

BBEdit 12.1.5

bbedit 12 1 5

TextMate 2.0-rc.10

textmate 2 0-rc 10

Visual Studio Code 1.27.2

visual studio code 1 27 2

Config settings:

  editor:
    autoIndent: false
    autoIndentOnPaste: false
    normalizeIndentOnPaste: false

System info:

Atom    : 1.30.0
Electron: 2.0.5
Chrome  : 61.0.3163.100
Node    : 8.9.3
yanamal commented 5 years ago

I am having the same issue on Atom 1.32.1 on Mac OSX

This behavior makes no sense to me, I can't even build a good mental model of what it's doing after scanning the linked forum post.

If I have all the "smart auto clever indent" things off, I want "paste" to paste exactly the characters that I have just copied. How can I accomplish that?

mhulse commented 5 years ago

How can I accomplish that?

I could be wrong, but I don't think you can at this time. :(

Note that this issue is marked as a bug.

Now, we either wait for someone to fix or try to do a PR.

Alternative would be to write a plugin, but at that point, time might be better spent trying to patch Atom’s core code.

I wish I had a better answer.

yanamal commented 5 years ago

Note that this issue is marked as a bug.

Ah, thanks for pointing that out. I got a serious whiff of "Will Not Fix, Working As Intended" from the forum thread (even though the person there technically was not speaking for the dev team)

for reference - I just tried "Command-SHIFT-V" instead of "Command-V" on a whim and it worked (i.e. it just pastes exactly what I had copied). In a way, that's sort of the opposite of what Command-SHIFT-V ("paste without formatting") usually does in rich-text editors, but whatever.

(also, based on the PR that implemented that functionality, the relevant option seems to be options.preserveTrailingLineIndentation; maybe I'll try to figure out how to expose/control that in my copious free time. That or go back to TextMate.)

mhulse commented 5 years ago

for reference - I just tried "Command-SHIFT-V" instead of "Command-V" on a whim and it worked (i.e. it just pastes exactly what I had copied). In a way, that's sort of the opposite of what Command-SHIFT-V ("paste without formatting") usually does in rich-text editors, but whatever.

Oooh, nice find! I had not even considered CMD + SHIFT + V!

I just added this to my keymap.cson:

'atom-workspace':
  'cmd-v': 'editor:paste-without-reformatting'

Not fully tested in numerous situation, but appears to fix the copy/paste issue.

Interesting ... Good find @yanamal!

AlanVolny commented 3 years ago

For non-mac folks, I put this:

'atom-workspace':
  'ctrl-v': 'editor:paste-without-reformatting'

into my keymap.cson file, and it worked! Atom is finally doing the sane thing! @mhulse Thanks guys!

I still don't really get why it's the default behavior - I can kinda get what they were going for (by copying the relative addition of a tab from the previous line, it could technically make nesting easier/faster) ... but it seems like that would be useful far less often than the default behavior used by every other text editor, but eh. Not an issue for me anymore.