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

[CLOSED] New lines always create white spaces #2918

Open
core-ai-bot opened this issue Aug 29, 2021 · 30 comments
Open

[CLOSED] New lines always create white spaces #2918

core-ai-bot opened this issue Aug 29, 2021 · 30 comments

Comments

@core-ai-bot
Copy link
Member

Issue by MiguelCastillo
Monday Mar 11, 2013 at 22:00 GMT
Originally opened as adobe/brackets#3100


When pressing enter to create a new line, white spaces are always inserted. For example, if you put the cursor at the beginning of a line and press enter, white spaces are inserted. This is really annoying if you use tabs.

This seems to be a recent regression.

Thanks,
Miguel

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Monday Mar 11, 2013 at 22:28 GMT


Change the Tab settings at the status bar to use Tabs instead of Spaces and it should insert tabs when indenting instead of spaces.

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Tuesday Mar 12, 2013 at 00:31 GMT


Hi, thank you for your response. I made sure I tried that before logging this issue. With either tabs or spaces selected in the status bar spaces are always inserted on new lines. I am running on sprint 21 with latest github changes. Did you have a second to try to reproduce the issue?

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Monday Mar 18, 2013 at 18:16 GMT


reviewed@njx

@core-ai-bot
Copy link
Member Author

Comment by njx
Tuesday Mar 19, 2013 at 06:14 GMT


@MiguelCastillo - I can't reproduce this on Mac in master or in sprint 21. If I create a blank JS file, switch the status bar item to Tabs, and then type function foo() { followed by Return, I get a hard tab (verified in hexdump). Are you on Mac or Win? Can you provide specific repro steps? Thanks.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Tuesday Mar 19, 2013 at 15:06 GMT


I can't reproduce on Win7 using same steps as NJ. I verified using the Brackets Show Whitespace extension (https://github.com/DennisKehrig/brackets-show-whitespace).

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 19:30 GMT


Sorry I haven't gotten back to this. It is rather easy to reproduce. I am on win7 x64...

@njx I followed your steps and I can reproduce the issue with no problems. I am attaching a screenshot below... Not sure if the screenshot can show the issue clearly, but I left the cursor right between the two spaces that were inserted. I also created a temp repo to access the Untitles.js file I created to show the issue in the screenshot. I have a swf that shows me reproducing the issue, so if you want to watch me type it let me know :)

  1. Create new js file.
  2. Type function(){
  3. Press Enter
  4. The cursor goes the next line and two spaces are inserted automatically.
  5. In the new line, type function(){
  6. Press enter. Now the new line has a tab!

The issue happens with any file...
I have had this issue for a while now... I am running into this issue with latest source from github and with installations. I am generally running with latest brackets code and latest codemirror source (FYI. they have removed the sql mode in the 3.1.1, which causes Brackets to fail to load).

https://github.com/MiguelCastillo/bracket-whitespace/blob/master/Untitled.js

image

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 19:41 GMT


I found what you need to do to reproduce the issue! Set you "Spaces" to a value other than "Tab Size". If your tab sizing is 4, change spaces to to 2 or 3 or whatever that isn't multiple of whatever tab sizing is...

I am sooo much happier now that I know how to get around the issue! Set white spaces and tabs to 4 :)

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Thursday Mar 21, 2013 at 20:15 GMT


@MiguelCastillo I am still not seeing the problem even with your new recipe. I am on Win7. Which version of Windows are you using.

Note that the CodeMirror SHA has been updated in Brackets, so use git submodule update to fix the sql mode problem. Does that fix this issue for you?

If not, can you install the Show Whitespace (https://github.com/DennisKehrig/brackets-show-whitespace) extension to help us all visualize the problem? Use Show > View Whitespace to enable it.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Thursday Mar 21, 2013 at 20:28 GMT


I just noticed in the status bar of your screen shot it says "Tab Size 4". Maybe that's not clear, but it indicates to use Tabs instead of spaces. Click on "Tab Size" once and it will change to "Spaces". Does that fix it?

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 20:43 GMT


AH!! Yes, that fixed it too. The usability for that setting is rather confusing. If the ui is displaying "Tab Size 4", I am expecting that tabs are being used for spaces. Switching to "Spaces 4" should give me spaces.

Hummm. The interesting thing is that when "Tab Spaces" and "Spaces" have the same value, they both insert tabs... I am not sure if this is an issue or just more confusion on my part :)

My question would then be what is the purpose of the little confusing setting?

Thanks for you help

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 20:44 GMT


Also@MiguelCastillo - do you have any extensions installed? We've noticed that some extensions seem to mess with autoindent, e.g. Emmet.

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 20:45 GMT


I have tried plain install of brackets with no extensions when providing feedback on the issue... The behavior is the same with and without the extensions I use, so the screenshots I have provided do show extensions being used. Here is a screenshot if my extensions' folder

image

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 20:47 GMT


@redmunds I ended up merging the sql addon manually while things get sorted out, so I am all set with the newest codemirror for now :)

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Thursday Mar 21, 2013 at 20:56 GMT


Brackets uses "soft tabs", so if you have your preference set to insert 4 spaces, using the keyboard left/right arrows will advance by 4 spaces at a time, the same as if you had tabs. Maybe that's what you're seeing.

The Display Whitespace extension will show you exactly what you have (but it can make the editor a little sluggish, so I disable it when not using it).

According to your screenshot, all of the extensions are installed in Brackets. Move them to the Roaming/Brackets/extensions/disabled folder to disable them.

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 21:43 GMT


As I mentioned before, I made sure to test without any extensions. Also tests with my extensions give the exact same result as without... The screenshot was just to show@njx that I am not using emmet whenever I have extensions active.

But yes@redmunds what you described is what I am seeing... That settings is rather confusing though. When I have "Spaces 4" on, I expect to get 4 spaces when pressing the return key and arrow keys will skip only 1 space at a time. And if I have "Tab Spaces 4" on I expect to get tabs when pressing the return key that are 4 spaces long and when pressing arrow keys, the cursor will jump 4 spaces at a time (a tab).

The setting gets even more confusing when spaces and tab spaces have different values. Not at all what I expected. As far as this issue is concerned, it seems like things are working as designed; whether good or bad usability.

Thanks for your feedback guys! :)
Miguel

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 21:48 GMT


Hi@MiguelCastillo - you're exactly right. Either the behavior of the settings have changed, or they were always confusing and we just didn't test this case thoroughly enough.

I believe the behavior we originally intended is that the "Tab Size/Spaces" control is independent of the number control, and switching between "Tab Size" and "Spaces" is supposed to just switch whether you're using hard or soft tabs. The intended behavior should be (if the number is set to "n"):

  • If "Tab Size" is showing, then we insert hard tabs, hard tabs are set to be n spaces in width, and the default autoindent unit is one hard tab (which looks like n spaces).
  • If "Spaces" is showing, then we insert spaces, we have "soft tab" behavior that skips over every n spaces, and the default autoindent unit is also n spaces.

That's clearly not what's happening now: if you set a value while "Spaces" is showing, and then switch to "Tab Size", the number also changes. I think that's just wrong.

I'll try to see when this broke--it's possible that it broke when we switched to CodeMirror v3; maybe the semantics of the indent-related options changed and we didn't notice.

Thanks for sticking with us and patiently explaining the problem!

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Thursday Mar 21, 2013 at 21:59 GMT


The Tab Size and the Space Indentation numbers are different values. So you could have Tab Size and 4 and Spaces and 2, since there are 3 different values set in the Editor (Spaces/Tabs, Tab Size and Spaces Indentation). I believe that is the correct behavior here.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Thursday Mar 21, 2013 at 22:04 GMT


I think this is working as designed. You can have different values for Spaces and Tabs.

Consider the case where you have Spaces 2 and Tab Size 4. Clicking on Spaces/Tab Size toggles between the settings.

When Spaces is showing, you'll get 2 spaces for each indent or Tab key. Brackets will not insert any Tab chars, but if you happen to have any in your page, they will be displayed a 4 spaces (which is why it says "Tab Size" instead of "Tabs"). And you get the soft tab behavior with spaces.

When you switch to Tab Size, then it's as you describe above. Brackets inserts a single Tab char and displays it to 4 spaces. You do not get soft tab behavior. The Spaces setting is not used, but it's remembered for when you switch back to Spaces.

@core-ai-bot
Copy link
Member Author

Comment by MiguelCastillo
Thursday Mar 21, 2013 at 22:10 GMT


It makes sense to have two independent values if you want to extra flexibility, I actually do like it. But consider the size of this thread to explain something as simple as tab/space... There is something inherently wrong with the usability.

LOL, the setting isn't that big of a deal. I am just happy I understand how to get my tabs inserted when pressing the return key :)

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 22:35 GMT


@redmunds - The problem occurs in the opposite case. If I set Spaces to 4 and Tabs to 2, then auto-indent indents 4 apparent spaces (2 hard tabs with 2-space widths), because of the hidden "4" setting on Spaces, which is not what I would expect--I wouldn't expect the hidden value to affect my current behavior.

I agree that you want to set all these things individually potentially, but I think the current design ends up conflating things in a confusing way.

I'm going to go ahead and call this "move to backlog" to discuss refining the UI here. Thanks everyone for your input!

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 22:36 GMT


Marking "move to backlog" and removing from Sprint 22.

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Thursday Mar 21, 2013 at 23:00 GMT


I see the problem now. It seems like we are using indentUnit in the wrong way, since it should apply for both tabs and spaces and not just spaces as we do. I have a simple fix for this that I could post soon.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Thursday Mar 21, 2013 at 23:13 GMT


@TomMalbran Brackets always inserts 1 tab char. The Tab Size setting is to tell the editor how to display the tab char. So indentUnit is always 1 with tabs. I think this is behaving as expected.

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Thursday Mar 21, 2013 at 23:19 GMT


If you have indentUnit set to 4 and Tab Size set to 2, then it inserts 2 tabs instead of 1. If you change the indentUnit option in CodeMirror to 2, then it will insert 1 tab as expected. It seems like CodeMirror uses the indentUnit for both tabs and spaces when indenting and not just spaces as how we handle it, so we need to change the indentUnit when changing the tabs.

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 23:33 GMT


@TomMalbran - yup, exactly. I think your description is the way it used to work (at least, it's what I would have expected to happen :)). I'll see if I can git bisect to find out whether the behavior actually changed at some point.

@core-ai-bot
Copy link
Member Author

Comment by njx
Thursday Mar 21, 2013 at 23:39 GMT


Nope, it looks like it's always worked this way, so it's not a regression. Leaving it as "move to backlog" so we can figure out what we want to do with it.

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Thursday Mar 21, 2013 at 23:43 GMT


I think it always worked like this. Check a look at my possible fix #3209.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Friday Mar 22, 2013 at 02:20 GMT


The problem occurs in the opposite case. If I set Spaces to 4 and Tabs to 2...

Yes, I'm seeing that problem.

@core-ai-bot
Copy link
Member Author

Comment by jasonsanjose
Friday Mar 22, 2013 at 03:53 GMT


Just catching up with this discussion. If it's helpful, the original pull request for this issue was #1801.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Friday Mar 22, 2013 at 15:21 GMT


This was auto-closed, so re-opening. This now behaves as it was designed, but we may want to change the design.

Note that this (some what cryptic?) design was reached because Brackets does not have a Preferences dialog. Once a Preferences dialog is added, the UI can be more verbose about these settings, and the status bar can be simplified.

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

No branches or pull requests

1 participant