diff --git a/static/js/editors.js b/static/js/editors.js index 585984b..ec41e0b 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -512,21 +512,16 @@ var editors = { tree.openFile(tree.fileTree.getNodeByTId(tId)); tree.fileTree.selectNode(wide.curNode); - var oldLine = wide.curEditor.getCursor().line; var line = $it.find(".position").data("line") - 1; var cursor = CodeMirror.Pos(line, $it.find(".position").data("ch") - 1); - wide.curEditor.setCursor(cursor); - var half = Math.floor(wide.curEditor.getScrollInfo().clientHeight / wide.curEditor.defaultTextHeight() / 2); - if (oldLine > line) { - var offset = line - half; - if (offset > 0) { - wide.curEditor.scrollIntoView(CodeMirror.Pos(offset, 0)); - } - } else if (oldLine < line) { - wide.curEditor.scrollIntoView(CodeMirror.Pos(line + half, 0)); - } + 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); wide.curEditor.focus(); }); @@ -563,25 +558,12 @@ var editors = { editors.tabs.setCurrent(id); wide.curEditor = editors.data[i].editor; var editor = wide.curEditor; - var oldLine = editor.getCursor().line + 1; - - if (oldLine === data.cursorLine) { - editor.focus(); - - return false; - } editor.setCursor(cursor); var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); - if (oldLine > data.cursorLine) { - var offset = data.cursorLine - half; - if (offset > 0) { - editor.scrollIntoView(CodeMirror.Pos(offset, 0)); - } - } else if (oldLine < data.cursorLine) { - editor.scrollIntoView(CodeMirror.Pos(data.cursorLine + half, 0)); - } + var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); + editor.scrollTo(0, cursorCoords.top); editor.focus(); @@ -721,7 +703,8 @@ var editors = { editor.setCursor(cursor); var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); - editor.scrollIntoView(CodeMirror.Pos(cursor.line + half, 0)); + var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local"); + editor.scrollTo(0, cursorCoords.top); wide.curEditor = editor; editors.data.push({ diff --git a/static/js/wide.js b/static/js/wide.js index 3d3c16b..be16cca 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -208,28 +208,17 @@ var wide = { $("#dialogGoLinePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true); }, "ok": function () { - var line = parseInt($("#dialogGoLinePrompt > input").val()); + var line = parseInt($("#dialogGoLinePrompt > input").val()) - 1; $("#dialogGoLinePrompt").dialog("close"); + var editor = wide.curEditor; - var oldLine = editor.getCursor().line + 1; + var cursor = editor.getCursor(); - if (oldLine === line) { - editor.focus(); - - return; - } - - editor.setCursor(CodeMirror.Pos(line - 1, 0)); + editor.setCursor(CodeMirror.Pos(line, cursor.ch)); var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2); - if (oldLine > line) { - var offset = line - half; - if (offset > 0) { - editor.scrollIntoView(CodeMirror.Pos(offset, 0)); - } - } else if (oldLine < line) { - editor.scrollIntoView(CodeMirror.Pos(line + half, 0)); - } + var cursorCoords = editor.cursorCoords({line: line - half, ch: cursor.ch}, "local"); + editor.scrollTo(0, cursorCoords.top); editor.focus(); }