viewport enhancement

This commit is contained in:
Liang Ding 2014-11-05 00:27:43 +08:00
parent 79103e4d92
commit 9577f26cba
3 changed files with 51 additions and 9 deletions

View File

@ -301,8 +301,8 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
part := found[:strings.LastIndex(found, ":")] part := found[:strings.LastIndex(found, ":")]
cursorSep := strings.LastIndex(part, ":") cursorSep := strings.LastIndex(part, ":")
path = found[:cursorSep] path = found[:cursorSep]
cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")] cursorLine, _ := strconv.Atoi(found[cursorSep+1 : strings.LastIndex(found, ":")])
cursorCh := found[strings.LastIndex(found, ":")+1:] cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:])
data["path"] = path data["path"] = path
data["cursorLine"] = cursorLine data["cursorLine"] = cursorLine

View File

@ -495,7 +495,6 @@ var editors = {
$(".toolbars").show(); $(".toolbars").show();
var id = wide.curNode.tId; var id = wide.curNode.tId;
// 光标位置
var cursor = CodeMirror.Pos(0, 0); var cursor = CodeMirror.Pos(0, 0);
if (data.cursorLine && data.cursorCh) { if (data.cursorLine && data.cursorCh) {
cursor = CodeMirror.Pos(data.cursorLine - 1, data.cursorCh - 1); cursor = CodeMirror.Pos(data.cursorLine - 1, data.cursorCh - 1);
@ -505,8 +504,28 @@ var editors = {
if (editors.data[i].id === id) { if (editors.data[i].id === id) {
editors.tabs.setCurrent(id); editors.tabs.setCurrent(id);
wide.curEditor = editors.data[i].editor; wide.curEditor = editors.data[i].editor;
wide.curEditor.setCursor(cursor); var editor = wide.curEditor;
wide.curEditor.focus(); 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));
}
editor.focus();
return false; return false;
} }
@ -621,6 +640,9 @@ var editors = {
editor.setCursor(cursor); editor.setCursor(cursor);
var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2);
editor.scrollIntoView(CodeMirror.Pos(cursor.line + half, 0));
wide.curEditor = editor; wide.curEditor = editor;
editors.data.push({ editors.data.push({
"editor": editor, "editor": editor,

View File

@ -208,8 +208,28 @@ var wide = {
"ok": function () { "ok": function () {
var line = parseInt($("#dialogGoLinePrompt > input").val()); var line = parseInt($("#dialogGoLinePrompt > input").val());
$("#dialogGoLinePrompt").dialog("close"); $("#dialogGoLinePrompt").dialog("close");
wide.curEditor.setCursor(CodeMirror.Pos(line - 1, 0)); var editor = wide.curEditor;
wide.curEditor.focus(); var oldLine = editor.getCursor().line + 1;
if (oldLine === line) {
editor.focus();
return;
}
editor.setCursor(CodeMirror.Pos(line - 1, 0));
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));
}
editor.focus();
} }
}); });
@ -453,7 +473,7 @@ var wide = {
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
// reset the save state // reset the save state
editor.doc.markClean(); editor.doc.markClean();
$(".edit-panel .tabs > div").each(function () { $(".edit-panel .tabs > div").each(function () {
var $span = $(this).find("span:eq(0)"); var $span = $(this).find("span:eq(0)");
@ -469,7 +489,7 @@ var wide = {
if (!path) { if (!path) {
return false; return false;
} }
var editor = wide.curEditor; var editor = wide.curEditor;
if (editor.doc.isClean()) { // no modification if (editor.doc.isClean()) { // no modification
return false; return false;