comment code

This commit is contained in:
Mathieu PATUREL
2017-01-12 09:22:40 +11:00
parent 37703e9bab
commit 5bbfb4606d
2 changed files with 35 additions and 5 deletions

View File

@ -73,13 +73,16 @@ def show_html(md_view, preview):
lambda href: sublime.run_command('open_url', lambda href: sublime.run_command('open_url',
{'url': href})) {'url': href}))
# set viewport position # get the "ratio" of the markdown view's position.
# 0 < y < 1 # 0 < y < 1
y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1] y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
# set the vector (position) for the preview
vector = [0, y * preview.layout_extent()[1]] vector = [0, y * preview.layout_extent()[1]]
# remove half of the viewport_extent.y to center it on the screen (verticaly) # remove half of the viewport_extent.y to center it on the screen (verticaly)
vector[1] -= preview.viewport_extent()[1] / 2 vector[1] -= preview.viewport_extent()[1] / 2
vector[1] = mini(vector[1], 0) # make sure the minimum is 0
vector[1] = 0 if vector < 0 else vector[1]
# the hide the first line
vector[1] += preview.line_height() vector[1] += preview.line_height()
preview.set_viewport_position(vector, animate=False) preview.set_viewport_position(vector, animate=False)

View File

@ -2,7 +2,6 @@
Hope you'll enjoy using MarkdownLivePreview! Hope you'll enjoy using MarkdownLivePreview!
![Sublime Text Forum](https://forum.sublimetext.com/uploads/st-forum-wide.png)
```python ```python
print('Hello world') print('Hello world')
@ -12,6 +11,34 @@ if DEBUG:
> Only a fool knows everything. A wise man knows how little he knows > Only a fool knows everything. A wise man knows how little he knows
Hello world
The only think I know right now is that Boxy Theme's just awesome. The only think I know right now is that Boxy Theme's just awesome.
t
h
i
s
-
i
s
![Sublime Text Forum](https://forum.sublimetext.com/uploads/st-forum-wide.png)
-
a
-
t
e
s
t