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, ":")]
cursorSep := strings.LastIndex(part, ":")
path = found[:cursorSep]
cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")]
cursorCh := found[strings.LastIndex(found, ":")+1:]
cursorLine, _ := strconv.Atoi(found[cursorSep+1 : strings.LastIndex(found, ":")])
cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:])
data["path"] = path
data["cursorLine"] = cursorLine

View File

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

View File

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