# last line detection

**URL:** <https://discuss.codemirror.net/t/last-line-detection/1148>\
**Category:** Uncategorized\
**Created:** [February 28, 2017, 5:32pm UTC](https://discuss.codemirror.net/t/last-line-detection/1148 "2017-02-28T17:32:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cferrell](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@cferrell](https://discuss.codemirror.net/u/cferrell)\
**Post date:** [February 28, 2017, 5:32pm UTC](https://discuss.codemirror.net/t/last-line-detection/1148/1 "2017-02-28T17:32:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [February 28, 2017, 7:57pm UTC](https://discuss.codemirror.net/t/last-line-detection/1148/2 "2017-02-28T19:57:54Z")

</div>

> [@cferrell](#):
>
> but this seems highly inefficient

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

---

<div class="post-metadata">

**Author:** ![cferrell](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@cferrell](https://discuss.codemirror.net/u/cferrell)\
**Post date:** [March 1, 2017, 3:29pm UTC](https://discuss.codemirror.net/t/last-line-detection/1148/3 "2017-03-01T15:29:43Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![dima1815](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@dima1815](https://discuss.codemirror.net/u/dima1815)\
**Post date:** [December 15, 2022, 11:15am UTC](https://discuss.codemirror.net/t/last-line-detection/1148/4 "2022-12-15T11:15:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [December 15, 2022, 11:30am UTC](https://discuss.codemirror.net/t/last-line-detection/1148/5 "2022-12-15T11:30:44Z")

</div>

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