Replace deprecated code in init.coffee


#1

A long, long time ago I was given advice on how to set up a built-in shortcut for simple things like adding a non-breaking space to html.

So I have

atom.workspaceView.command 'editor:insert-nbsp', ->
atom.workspace.getActiveEditor()?.insertText(' ')

Which is apparently deprecated. What’s the modern way to do this sort of thing?


#2

I am just typing this in browser window without testing, but I think you want:

atom.commands.add 'atom-text-editor',
  'editor:insert-nbsp': (event) ->
    editor = @getModel()
    editor.insertText(' ')

See examples here for more info:


#3

I just tested @jessegrosjean’s solution and it worked.


#4

Yes, it did. Thanks. Now only 3rd party items are flagged by Deprecation Cop.

I also needed to change my keymap from

'.editor:not(.mini)': 

to

 'atom-text-editor:not(.mini)':

#5

I suggest you should use atom-text-editor:not([mini]) instead.