preview window is scrolling according to cursor position in markdown buffer
This commit is contained in:
parent
a9e85581f8
commit
0c53ded3dc
@ -95,20 +95,31 @@
|
||||
(mdpm:sent-preview-to mdpm:local-client))
|
||||
|
||||
(defun mdpm:sent-preview-to (websocket)
|
||||
(when markdown-preview-mode
|
||||
(markdown markdown-output-buffer-name))
|
||||
(with-current-buffer (get-buffer markdown-output-buffer-name)
|
||||
(websocket-send-text websocket
|
||||
(concat
|
||||
"<div>"
|
||||
"<span id='style'>"
|
||||
markdown-preview-style
|
||||
"</span>"
|
||||
"<div id='content'>"
|
||||
(buffer-substring-no-properties (point-min) (point-max))
|
||||
"</div>"
|
||||
"</div>")
|
||||
)))
|
||||
(let ((mark-position-percent
|
||||
(number-to-string
|
||||
(truncate
|
||||
(* 100
|
||||
(/
|
||||
(float (line-number-at-pos))
|
||||
(count-lines (point-min) (point-max))))))))
|
||||
|
||||
(when markdown-preview-mode
|
||||
(markdown markdown-output-buffer-name))
|
||||
(with-current-buffer (get-buffer markdown-output-buffer-name)
|
||||
(websocket-send-text websocket
|
||||
(concat
|
||||
"<div>"
|
||||
"<span id='style'>"
|
||||
markdown-preview-style
|
||||
"</span>"
|
||||
"<span id='position-percentage'>"
|
||||
mark-position-percent
|
||||
"</span>"
|
||||
"<div id='content'>"
|
||||
(buffer-substring-no-properties (point-min) (point-max))
|
||||
"</div>"
|
||||
"</div>")
|
||||
))))
|
||||
|
||||
(defun mdpm:start ()
|
||||
(mdpm:start-websocket-server)
|
||||
|
@ -5,6 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
|
||||
<title>Markdown preview</title>
|
||||
<link href="http://thomasf.github.io/solarized-css/solarized-dark.min.css" rel="stylesheet"></link>
|
||||
<style>
|
||||
code, kbd, pre, samp {
|
||||
line-height: 1.2em;
|
||||
}
|
||||
</style>
|
||||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||
<script>
|
||||
(function($, undefined) {
|
||||
@ -23,6 +28,8 @@
|
||||
socket.onmessage = function(event) {
|
||||
loadCSS($(event.data).find("#style").text());
|
||||
$("#markdown-body").html($(event.data).find("#content").html());
|
||||
var scroll = $(document).height() * ($(event.data).find("#position-percentage").html() / 100);
|
||||
$("html, body").animate({ scrollTop: scroll }, 600);
|
||||
};
|
||||
socket.onerror = function(error) {
|
||||
alert("Error: " + error.message);
|
||||
|
Loading…
Reference in New Issue
Block a user