From 1ed57dc5dac766218d513760163b6d0cfbdd5ac9 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 4 Jan 2015 10:11:08 +0800 Subject: [PATCH] #199 --- static/js/wide.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/static/js/wide.js b/static/js/wide.js index 854f23c..8aa4f97 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -55,9 +55,16 @@ var wide = { $("#outline li").dblclick(function () { var $it = $(this), - cursor = CodeMirror.Pos($it.data('line'), $it.data("ch")); - wide.curEditor.setCursor(cursor); - wide.curEditor.focus(); + cursor = CodeMirror.Pos($it.data('line'), $it.data("ch")); + + var editor = wide.curEditor; + editor.setCursor(cursor); + + var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); + var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); + editor.scrollTo(0, cursorCoords.top); + + editor.focus(); }); } });