How to know what lines / chars are currently visible in a textarea?

前端 未结 1 1301
感情败类
感情败类 2021-01-17 16:57

Online editor with \"live preview\": there is a textarea on the left and a preview div on the right. Whenever the textarea changes, the preview is updated.

This work

相关标签:
1条回答
  • 2021-01-17 17:50

    Well, as a crazy way for doing it you can look how ACE converts the text into canvas-drawn lines. I assume with this approach you can determine the exact position (or better to say, the exact line objects that are currently visible.

    But this could also be a kind of vicious circle if the canvas-generated text is compatible in complexity to what you are having in the preview.

    Alternatively you can use a fixed-width font which will give you a knowledge of the exact number of chars in the single line, and thus a way of calculating the exact first / last lines.

    0 讨论(0)
提交回复
热议问题