scroll preview when writing: OK

it does not show at the center when possible, though
This commit is contained in:
math2001
2016-11-26 09:31:10 +11:00
parent 48e0420816
commit 100b712ef1
3 changed files with 19 additions and 3 deletions

View File

@ -65,6 +65,7 @@ def create_preview(window, md_view):
preview_settings = preview.settings()
preview_settings.set('gutter', False)
preview_settings.set('scroll_past_end', False)
preview_settings.set('is_markdown_preview', True)
preview_settings.set('markdown_view_id', md_view.id())
@ -83,6 +84,8 @@ def show_html(md_view, preview):
html,
sublime.LAYOUT_INLINE,
lambda href: sublime.run_command('open_url', {'url': href}))
y = md_view.layout_extent()[1] / md_view.text_to_layout(md_view.sel()[0].begin())[1]
preview.set_viewport_position((0, y * preview.layout_extent()[1]), False)
def get_view_content(view):
return view.substr(sublime.Region(0, view.size()))

View File

@ -2,6 +2,7 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
#### The Zen of Python, by Tim Peters
> Beautiful is better than ugly.
@ -40,7 +41,19 @@ This is some `code`
- a
- list
1. an
1. and
2. other
3. list
this
is
a
lot
of
paragraph

View File

@ -1,8 +1,8 @@
# todo
- sync scroll
- add message in status bar
- add **custom css** feature
- sync scroll @done @improve: scroll preview to center when possible
- regive focus to the right markdown view @done
- set the title of the preview @done
- disable previewing when the preview is closed @done