last line detection

I am in need of detecting when the cursor is on the last line (to disable some CSS) - I can do this using the onSelectionChange handler, but this seems highly inefficient, on every cursor move, etc I’m getting the total lines, then checking if the cursor is on that line.

is there a more efficient way of doing this?

No, it’s fine. Calling .lastLine() is very cheap.

Thank you!

Hi @marijn - is there a way to know whether you are on the last line whilst in the token method of a custom mode? There are only two parameters that this function takes: stream and state and no reference to the editor itself.

No, stream-style modes can only see their state and the current line (so that their results can be reused as the document changes).

1 Like