Getting current line height of the editor


#1

Does anyone know how to get the current line height of the editor? The @component-line-height variable does not seem to change at all, where as this line height (24px):

which is what I’m looking for, changes with the current zoom level. I need a way to get this programmatically. I’ve tried getting it from a dummy div and adding the line class onto it, but it seems not to set the value explicitly in the class style. Thanks!


#2

What about window.getComputedStyle(line).lineHeight?


#3

There doesn’t seem to be a way to create an element with the line class for some reason. Document.createElement(“div”).classList.add(“line”) doesn’t have any associated styles with it so that didn’t work for me.


#4

You can use

var lineHeight = textEditor.getLineHeightInPixels();

It will return an incorrect value when the text editor’s element hasn’t been attached to the DOM before and/or has been visible.

You should get the same value by doing

Math.floor(atom.config.get('editor.fontSize') * atom.config.get('editor.lineHeight'));

but that depends on chrome specific behaviour (the rounding down) so it wouldn’t be desirable to use it, even though it is more likely to return the correct value :frowning: