sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
810 stars 39 forks source link

Copy-pasting a .patch content with `+\t...` is pasted as `+ ` #4569

Open stdedos opened 3 years ago

stdedos commented 3 years ago

Description

For mock patch

diff a b
--- a
+++ b
@@ -1,3 +1,6 @@
+   546
+       546
+   546
 a
 b
 c

After copy-pasting it in a file delimited as "Spaces: 2", it becomes:

diff a b
--- a
+++ b
@@ -1,3 +1,6 @@
+ 546
+   546
+ 546
 a
 b
 c

Steps to reproduce

  1. Start Sublime Text in safe mode
  2. Second step
  3. Third step

Expected behavior

File is pasted as-is

Actual behavior

File has its whitespace modified

Environment

jfcherng commented 3 years ago

Confirmed in 4109. But I don't think it can be fixed easily... since "pasted as-is" causes bad UX in other scenarios.

keith-hall commented 3 years ago

https://github.com/sublimehq/Packages/pull/2729/files

stdedos commented 3 years ago

I have read the PR.

Have you tried my example with the PR applied though? I am not sure how much exactly those two are related.

BenjaminSchaaf commented 3 years ago

Have you tried my example with the PR applied though? I am not sure how much exactly those two are related.

"translate_tabs_to_spaces" will translate tabs to spaces when pasting.

jfcherng commented 3 years ago

For my understanding, OP's issue is pasting patch into another file (for example, a PHP file). If that's the case, setting translate_tabs_to_spaces in Diff doesn't help. It should be set in PHP but that makes no sense.

BenjaminSchaaf commented 3 years ago

OP's issue is pasting patch into another file (for example, a PHP file)

Considering that the highlighting is clearly for diffs I don't think this is a given without the actual steps to reproduce filled out. @stdedos can you please complete the issue template, specifically the steps to reproduce (including using safe mode). Thanks.

stdedos commented 3 years ago

"translate_tabs_to_spaces" will translate tabs to spaces when pasting.

Every tab, no matter where it is? 😕

Shouldn't settings like that affect only indentation?

BenjaminSchaaf commented 3 years ago

That's not generally the desired effect, tab can be used to align things using spaces.

stdedos commented 3 years ago

OP's issue is pasting patch into another file (for example, a PHP file)

Considering that the highlighting is clearly for diffs I don't think this is a given without the actual steps to reproduce filled out. @stdedos can you please complete the issue template, specifically the steps to reproduce (including using safe mode). Thanks.

Please try to read the whole issue:

After copy-pasting it in a file delimited as "Spaces: 2"

and

Start Sublime Text in safe mode

Emphasis mine

I am not going to type things twice, just because you cannot see 2 feet to your left and right.

BenjaminSchaaf commented 3 years ago

Sorry, but that doesn't clear anything up. Is it a new file that you have set the indentation level manually to 2 spaces on? Is it a new file with the indentation level defaulted to 2 from your settings? Does it happen in safe mode?

This is why I asked for steps to reproduce using safe mode and why it's in the issue template.

stdedos commented 3 years ago

Sorry, but that doesn't clear anything up. Is it a new file that you have set the indentation level manually to 2 spaces on? Is it a new file with the indentation level defaulted to 2 from your settings?

It is a file that exists, which is a different file that the one its code is presented, that patch is pasted verbatim into, with detected indentation as "Spaces: 2"

Does it happen in safe mode?

YES, and it's literally in the issue text!

jfcherng commented 3 years ago

Then I think my guess is correct.

BenjaminSchaaf commented 3 years ago

It is a file that exists, which is a different file that the one its code is presented, that patch is pasted verbatim into, with detected indentation as "Spaces: 2"

Is the file you're pasting into empty and is it saved? Sublime Text doesn't detect an indentation level for the snippet you posted, do you have the default set to 2 perhaps?

YES, and it's literally in the issue text!

Since you didn't fill out the steps to reproduce, it was not clear whether you were reproducing this issue in safe mode or just ignored that section of the template.

stdedos commented 3 years ago

It is a file that exists, has data, it is saved as valid XML prior to this process, and with its automatically detected indentation being "Spaces: 2", which is a different file that the one its code is presented, that in the process of editing it, the patch is pasted verbatim into.

BenjaminSchaaf commented 3 years ago

Thanks for clarifying. This is currently expected behavior as indentation detection turns on "translate_tabs_to_spaces" which also applies when pasting. A workable solution may be to add another option to that setting for only translating tabs used for indentation.

stdedos commented 3 years ago

It wasn't on versions 3xxx IIRC, so that sounds like a bug.

I am not sure how much I appreciate mangling my pasted text unless some translate_any_tab_to_space setting is globally set i.e. I don't want to work with tabs throughout this program/project.

BenjaminSchaaf commented 3 years ago

This behavior hasn't changed since ST3 and I can reproduce it there.