Sometimes tab inserts spaces, even with soft tabs off


#1

Sometimes atom decided to stop inserting tab characters when I hit the tab key on my keyboard. I’ve been unable to come up with reproducible steps to reproduce, it seems to happen every other day or so.

Restarting my editor sometimes fixes it.

When I enter this state, the following occurs:

  • I’m unable to even paste a tab character at the beginning of a line.
  • Any indentation action seems to replace tabs with spaces.

As we are required to use tabs for our coding conventions, every time this happens I have to drop back to vim to fix things.


Can't enter hard tab
#2

Is it a particular kind of file that it always happens in? Did you recently install any packages? Some people have had strange interactions with custom UI themes and keyboard actions, have you tried going back to the standard themes?

Not sure I have any better ideas than you but perhaps these are some things you can try to help track it down …


#3

It only happens with cs files. I installed the Language Css package, maybe a bug in that?


#4

Do you mean CSS files? Or CSharp files?


#5

CSharp files (.cs extension).


#6

For some reason the editor will autodetect spaces/tabs in each file, and that overrides the preference setting. It will switch to inserting spaces for a file where any line begins with any number of spaces. This happened to me with a file that contained multiline comments with lines beginning with a space and asterisk. It is very annoying.


#7

I agree.

I find it unacceptable, and have had to stop using atom until I can turn it off. :frowning:


#8

If you want to force it to use your soft tabs setting, you can make a change in /Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js.
In TextBuffer.prototype.usesSoftTabs on line 825, just add a return false; at the start of the function.

Unfortunately this will break when Atom updates.


#9

Thanks!

I filed an issue here:


#10

Perhaps you could submit a pull request for the Text Buffer package?


#11

Rather than just returning false, we should probably look to see the if the user is using softTabs. As a result I think the following would be a more appropriate fix than simply returning false.

TextBuffer.prototype.usesSoftTabs = function() {
      if (!atom.config.get('editor.softTabs')) { return false; }
      var match, row, _i, _ref1;

or in CoffeeScript

return false  unless atom.config.get("editor.softTabs")

Updated: Pull Request at https://github.com/atom/text-buffer/pull/12


#12

This also seems to be the case in javascript files. Related?


#13

Happens in PHP, HTML, as well as mixed HTML/PHP. It probably happens in most syntax modes to be quite honest. It’s a maddening bug.


#14

So is there a work around or solution to this? Maybe something in the config.cson or init.coffee?


#15

@GameGamer43
couldn’t we put this in the init.coffee file?


#16

@middle8media I haven’t tested this at all, but if you wanted to do this in the init.coffee file, you would add the following:

editor = atom.workspace.getActiveEditor()
editor.buffer.usesSoftTabs = ->
      return false unless atom.config.get("editor.softTabs")
      for row in [0..@getLastRow()]
            if match = @lineForRow(row).match(/^\s/)
                  return match[0][0] != '\t' 

#17

Regarding the pull request that was denied due to use of the atom global - couldn’t the issue therefore be solved in one of two ways:

  1. The ‘uses soft tabs’ setting is passed to TextBuffer as a constructor parameter or a setter-like method. This way we don’t rely on the atom global, only the fact that TextBuffer should care about soft tabs or not.

  2. The code that actually calls TextBuffer::usesSoftTabs() needs to have the code from the PR so the reliance on the atom global is no longer in TextBuffer but in whatever calls it. If whatever calls it is also in the atom/text-buffer package, then maybe whatever calls that and so on up the chain till it’s the atom/atom package. Obviously it could be the case that that won’t work as it’s all done in atom/text-buffer but if that’s the case then surely it needs to know about the soft tabs preference anyway so has it stored somewhere passed in from atom’s core. Anyway, I’m not sure how easy it is to tell what actually calls TextBuffer::usesSoftTabs() (I tried setting a breakpoint and then opening a file and it didn’t stop so I’m out of ideas) so can’t tell how viable this solution is.

Just a couple of ideas, anyway.


#18

Just putting in another vote here that a fix for this is needed. As far as I’m concerned, it’s a bug that makes disabling the “soft tabs” option a bit of a farce.


#19

Please, another vote to fix this. It’s an incredible pain point when editing C# files here.


#20

I’m pretty sure this was fixed: https://github.com/atom/atom/pull/2045

It works perfectly for me now.