This commit is contained in:
Van 2014-12-09 16:46:52 +08:00
parent 41ba5a2d1a
commit f0058c3602
2 changed files with 165 additions and 137 deletions

View File

@ -184,7 +184,8 @@ var editors = {
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断 if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
menu.disabled(['save-all', 'build', 'run', 'go-test', 'go-get', 'go-install', menu.disabled(['save-all', 'build', 'run', 'go-test', 'go-get', 'go-install',
'find', 'find-next', 'find-previous', 'replace', 'replace-all', 'find', 'find-next', 'find-previous', 'replace', 'replace-all',
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment']); 'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
'edit']);
$(".toolbars").hide(); $(".toolbars").hide();
} }
@ -433,6 +434,127 @@ var editors = {
}); });
}; };
CodeMirror.commands.copyLinesDown = function (cm) {
var content = '',
selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
for (var i = from.line, max = to.line; i <= max; i++) {
if (to.ch !== 0 || i !== max) { // 下一行选中为0时不应添加内容
content += '\n' + cm.getLine(i);
}
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange(content, CodeMirror.Pos(replaceToLine));
var offset = replaceToLine - from.line + 1;
cm.setSelection(CodeMirror.Pos(from.line + offset, from.ch),
CodeMirror.Pos(to.line + offset, to.ch));
};
CodeMirror.commands.copyLinesUp = function (cm) {
var content = '',
selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
for (var i = from.line, max = to.line; i <= max; i++) {
if (to.ch !== 0 || i !== max) { // 下一行选中为0时不应添加内容
content += '\n' + cm.getLine(i);
}
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange(content, CodeMirror.Pos(replaceToLine));
cm.setSelection(CodeMirror.Pos(from.line, from.ch),
CodeMirror.Pos(to.line, to.ch));
};
CodeMirror.commands.moveLinesUp = function (cm) {
var selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
if (from.line === 0) {
return false;
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange('\n' + cm.getLine(from.line - 1), CodeMirror.Pos(replaceToLine));
if (from.line === 1) {
// 移除第一行的换行
cm.replaceRange('', CodeMirror.Pos(0, 0),
CodeMirror.Pos(1, 0));
} else {
cm.replaceRange('', CodeMirror.Pos(from.line - 2, cm.getLine(from.line - 2).length),
CodeMirror.Pos(from.line - 1, cm.getLine(from.line - 1).length));
}
cm.setSelection(CodeMirror.Pos(from.line - 1, from.ch),
CodeMirror.Pos(to.line - 1, to.ch));
};
CodeMirror.commands.moveLinesDown = function (cm) {
var selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
if (to.line === cm.lastLine()) {
return false;
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
// 把选中的下一行添加到选中区域的上一行
if (from.line === 0) {
cm.replaceRange(cm.getLine(replaceToLine + 1) + '\n', CodeMirror.Pos(0, 0));
} else {
cm.replaceRange('\n' + cm.getLine(replaceToLine + 1), CodeMirror.Pos(from.line - 1));
}
// 删除选中的下一行
cm.replaceRange('', CodeMirror.Pos(replaceToLine + 1, cm.getLine(replaceToLine + 1).length),
CodeMirror.Pos(replaceToLine + 2, cm.getLine(replaceToLine + 2).length));
cm.setSelection(CodeMirror.Pos(from.line + 1, from.ch),
CodeMirror.Pos(to.line + 1, to.ch));
};
CodeMirror.commands.jumpToDecl = function (cm) { CodeMirror.commands.jumpToDecl = function (cm) {
var cur = wide.curEditor.getCursor(); var cur = wide.curEditor.getCursor();
@ -574,7 +696,8 @@ var editors = {
menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install', menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install',
'find', 'find-next', 'find-previous', 'replace', 'replace-all', 'find', 'find-next', 'find-previous', 'replace', 'replace-all',
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment']); 'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
'edit']);
var textArea = document.getElementById("editor" + id); var textArea = document.getElementById("editor" + id);
textArea.value = data.content; textArea.value = data.content;
@ -623,123 +746,10 @@ var editors = {
windows.maxEditor(); windows.maxEditor();
} }
}, },
"Shift-Ctrl-Up": function (cm) { "Shift-Ctrl-Up": "copyLinesUp",
var content = '', "Shift-Ctrl-Down": "copyLinesDown",
selectoion = cm.listSelections()[0]; "Shift-Alt-Up": "moveLinesUp",
"Shift-Alt-Down": "moveLinesDown"
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
for (var i = from.line, max = to.line; i <= max; i++) {
if (to.ch !== 0 || i !== max) { // 下一行选中为0时不应添加内容
content += '\n' + cm.getLine(i);
}
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange(content, CodeMirror.Pos(replaceToLine));
cm.setSelection(CodeMirror.Pos(from.line, from.ch),
CodeMirror.Pos(to.line, to.ch));
},
"Shift-Ctrl-Down": function (cm) {
var content = '',
selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
for (var i = from.line, max = to.line; i <= max; i++) {
if (to.ch !== 0 || i !== max) { // 下一行选中为0时不应添加内容
content += '\n' + cm.getLine(i);
}
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange(content, CodeMirror.Pos(replaceToLine));
var offset = replaceToLine - from.line + 1;
cm.setSelection(CodeMirror.Pos(from.line + offset, from.ch),
CodeMirror.Pos(to.line + offset, to.ch));
},
"Shift-Alt-Up": function (cm) {
var selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
if (from.line === 0) {
return false;
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
cm.replaceRange('\n' + cm.getLine(from.line - 1), CodeMirror.Pos(replaceToLine));
if (from.line === 1) {
// 移除第一行的换行
cm.replaceRange('', CodeMirror.Pos(0, 0),
CodeMirror.Pos(1, 0));
} else {
cm.replaceRange('', CodeMirror.Pos(from.line - 2, cm.getLine(from.line - 2).length),
CodeMirror.Pos(from.line - 1, cm.getLine(from.line - 1).length));
}
cm.setSelection(CodeMirror.Pos(from.line - 1, from.ch),
CodeMirror.Pos(to.line - 1, to.ch));
},
"Shift-Alt-Down": function (cm) {
var selectoion = cm.listSelections()[0];
var from = selectoion.anchor,
to = selectoion.head;
if (from.line > to.line) {
from = selectoion.head;
to = selectoion.anchor;
}
if (to.line === cm.lastLine()) {
return false;
}
// 下一行选中为0时应添加到上一行末
var replaceToLine = to.line;
if (to.ch === 0) {
replaceToLine = to.line - 1;
}
// 把选中的下一行添加到选中区域的上一行
if (from.line === 0) {
cm.replaceRange(cm.getLine(replaceToLine + 1) + '\n', CodeMirror.Pos(0, 0));
} else {
cm.replaceRange('\n' + cm.getLine(replaceToLine + 1), CodeMirror.Pos(from.line - 1));
}
// 删除选中的下一行
cm.replaceRange('', CodeMirror.Pos(replaceToLine + 1, cm.getLine(replaceToLine + 1).length),
CodeMirror.Pos(replaceToLine + 2, cm.getLine(replaceToLine + 2).length));
cm.setSelection(CodeMirror.Pos(from.line + 1, from.ch),
CodeMirror.Pos(to.line + 1, to.ch));
}
} }
}); });

View File

@ -59,48 +59,66 @@
<span>{{.i18n.edit}}</span> <span>{{.i18n.edit}}</span>
<div class="frame"> <div class="frame">
<ul> <ul>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.undo();wide.curEditor.focus()}">
<span>{{.i18n.undo}}</span> <span>{{.i18n.undo}}</span>
<span class="fn-right ft-small">Ctrl-Z</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.redo();wide.curEditor.focus()}">
<span>{{.i18n.redo}}</span> <span>{{.i18n.redo}}</span>
<span class="fn-right ft-small">Ctrl-Y</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled" onclick="alert('Dev In Progress')">
<span>{{.i18n.cut}}</span> <span>{{.i18n.cut}}</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled" onclick="alert('Dev In Progress')">
<span>{{.i18n.copy}}</span> <span>{{.i18n.copy}}</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled" onclick="alert('Dev In Progress')">
<span>{{.i18n.paste}}</span> <span>{{.i18n.paste}}</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('selectAll');wide.curEditor.focus()}">
<span>{{.i18n.select_all}}</span> <span>{{.i18n.select_all}}</span>
<span class="fn-right ft-small">Ctrl-A</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled" onclick="alert('Dev In Progress')">
<span>{{.i18n.select_identifier}}</span> <span>{{.i18n.select_identifier}}</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('gotoLine')}">
<span>{{.i18n.goto_line}}</span> <span>{{.i18n.goto_line}}</span>
<span class="fn-right ft-small">Ctrl-L</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('deleteLine');wide.curEditor.focus()}">
<span>{{.i18n.delete_line}}</span> <span>{{.i18n.delete_line}}</span>
<span class="fn-right ft-small">Ctrl-E</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('copyLinesUp');wide.curEditor.focus()}">
<span>{{.i18n.copy_lines_up}}</span> <span>{{.i18n.copy_lines_up}}</span>
<span class="fn-right ft-small">Shift-Ctrl-Up</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('copyLinesDown');wide.curEditor.focus()}">
<span>{{.i18n.copy_lines_down}}</span> <span>{{.i18n.copy_lines_down}}</span>
<span class="fn-right ft-small">Shift-Ctrl-Down</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('moveLinesUp');wide.curEditor.focus()}">
<span>{{.i18n.move_lines_up}}</span> <span>{{.i18n.move_lines_up}}</span>
<span class="fn-right ft-small">Shift-Alt-Up</span>
</li> </li>
<li onclick="alert('Dev In Progress')"> <li class="edit disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('moveLinesDown');wide.curEditor.focus()}">
<span>{{.i18n.move_lines_down}}</span> <span>{{.i18n.move_lines_down}}</span>
<span class="fn-right ft-small">Shift-Alt-Down</span>
</li> </li>
</ul> </ul>
</div> </div>
@ -110,23 +128,23 @@
<div class="frame"> <div class="frame">
<ul> <ul>
<li class="format disabled" <li class="format disabled"
onclick="if (!$(this).hasClass('disabled')){wide.fmt(editors.getCurrentPath(), wide.curEditor)}"> onclick="if (!$(this).hasClass('disabled')){wide.fmt(editors.getCurrentPath(), wide.curEditor);wide.curEditor.focus()}">
<span>{{.i18n.format}}</span> <span>{{.i18n.format}}</span>
<span class="fn-right ft-small">Ctrl-Shift-F</span> <span class="fn-right ft-small">Ctrl-Shift-F</span>
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li class="autocomplete disabled" <li class="autocomplete disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('autocompleteAnyWord')}"> onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('autocompleteAnyWord');wide.curEditor.focus()}">
<span>{{.i18n.autocomplete}}</span> <span>{{.i18n.autocomplete}}</span>
<span class="fn-right ft-small">Ctrl-\</span> <span class="fn-right ft-small">Ctrl-\</span>
</li> </li>
<li class="jump-to-decl disabled" <li class="jump-to-decl disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('jumpToDecl')}"> onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('jumpToDecl');wide.curEditor.focus()}">
<span>{{.i18n.jump_to_decl}}</span> <span>{{.i18n.jump_to_decl}}</span>
<span class="fn-right ft-small">Ctrl-B</span> <span class="fn-right ft-small">Ctrl-B</span>
</li> </li>
<li class="expr-info disabled" <li class="expr-info disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('exprInfo')}"> onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('exprInfo');wide.curEditor.focus()}">
<span>{{.i18n.show_expr_info}}</span> <span>{{.i18n.show_expr_info}}</span>
<span class="fn-right ft-small">Ctrl-I</span> <span class="fn-right ft-small">Ctrl-I</span>
</li> </li>
@ -137,7 +155,7 @@
</li> </li>
<li class="hr"></li> <li class="hr"></li>
<li class="toggle-comment disabled" <li class="toggle-comment disabled"
onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('toggleComment')}"> onclick="if (!$(this).hasClass('disabled')){wide.curEditor.execCommand('toggleComment');wide.curEditor.focus()}">
<span>{{.i18n.toggle_comment}}</span> <span>{{.i18n.toggle_comment}}</span>
<span class="fn-right ft-small">Ctrl-/</span> <span class="fn-right ft-small">Ctrl-/</span>
</li> </li>