From 100b712ef1836b3fc07576bf78759c232cff0bd3 Mon Sep 17 00:00:00 2001 From: math2001 Date: Sat, 26 Nov 2016 09:31:10 +1100 Subject: [PATCH] scroll preview when writing: OK it does not show at the center when possible, though --- md_in_popup.py | 3 +++ sample.md | 17 +++++++++++++++-- todo.md | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/md_in_popup.py b/md_in_popup.py index 3d4b7fa..04d9401 100644 --- a/md_in_popup.py +++ b/md_in_popup.py @@ -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())) diff --git a/sample.md b/sample.md index 7fe125a..d4b7f56 100644 --- a/sample.md +++ b/sample.md @@ -1,6 +1,7 @@ # Hello world! -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. +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 @@ -40,7 +41,19 @@ This is some `code` - a - list -1. an +1. and 2. other 3. list + +this + +is + +a + +lot + +of + +paragraph \ No newline at end of file diff --git a/todo.md b/todo.md index 0b1e1e4..e800d3a 100644 --- a/todo.md +++ b/todo.md @@ -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