atom / flight-manual.atom.io

📖 Documentation for Atom, generated by nanoc, hosted by GitHub Pages
https://flight-manual.atom.io
Other
640 stars 1.54k forks source link

Fix `this` context in JS snippets & increase consistency #559

Closed Aerijo closed 5 years ago

Aerijo commented 5 years ago

RIP template links.

Fixes https://github.com/atom/atom/issues/19855

Description

Changes the function kind so that the context of this is now TextEditorElement and this.getModel() works. Also changed the following snippet to use this.getModel() as well.

Semicolons introduced for consistency with Atom code base (and the other snippets in here I came across).

Alternatives

TextEditorElement is undocumented. Technically could replace this.getModel() with atom.workspace.getActiveTextEditor(), to avoid an undocumented method call. However, getModel feels more correct in terms of linking the event to the right editor; it is possible for atom.workspace.getActiveTextEditor() to return a different editor, or none at all, whereas we can (probably) safely assume this.getModel() will always return the correct editor.

rsese commented 5 years ago

Thanks @Aerijo :+1: @lee-dohm - I remember you converted examples to JavaScript in https://github.com/atom/flight-manual.atom.io/pull/512, does this look good to you?