asciidoctor / atom-asciidoc-preview

⚛ AsciiDoc preview for the Atom editor.
https://atom.io/packages/asciidoc-preview
MIT License
141 stars 42 forks source link

Find nearest block when syncing scroll position #219

Open mojavelinux opened 7 years ago

mojavelinux commented 7 years ago

Description

In the solution to #82, the preview window is only scrolled if the cursor line matches the start line of a block. If the cursor is not positioned at the start line of a block, the sync logic should find the block nearest to the cursor line and scroll to that block.

Proposed solution

There are at least two ways to solve this problem. First, we could account for every line when building the block position index. That way, no change is needed to the scrollPreview method (and resolution during the event is immediate). The other solution is to attempt to do this calculation in the scrollPreview method.