This commit is contained in:
parent
41ba5a2d1a
commit
f0058c3602
|
@ -184,7 +184,8 @@ var editors = {
|
|||
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
|
||||
menu.disabled(['save-all', 'build', 'run', 'go-test', 'go-get', 'go-install',
|
||||
'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();
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
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',
|
||||
'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);
|
||||
textArea.value = data.content;
|
||||
|
@ -623,123 +746,10 @@ var editors = {
|
|||
windows.maxEditor();
|
||||
}
|
||||
},
|
||||
"Shift-Ctrl-Up": 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));
|
||||
},
|
||||
"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));
|
||||
}
|
||||
"Shift-Ctrl-Up": "copyLinesUp",
|
||||
"Shift-Ctrl-Down": "copyLinesDown",
|
||||
"Shift-Alt-Up": "moveLinesUp",
|
||||
"Shift-Alt-Down": "moveLinesDown"
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -59,48 +59,66 @@
|
|||
<span>{{.i18n.edit}}</span>
|
||||
<div class="frame">
|
||||
<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 class="fn-right ft-small">Ctrl-Z</span>
|
||||
</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 class="fn-right ft-small">Ctrl-Y</span>
|
||||
</li>
|
||||
<li class="hr"></li>
|
||||
<li onclick="alert('Dev In Progress')">
|
||||
<li class="edit disabled" onclick="alert('Dev In Progress')">
|
||||
<span>{{.i18n.cut}}</span>
|
||||
</li>
|
||||
<li onclick="alert('Dev In Progress')">
|
||||
<li class="edit disabled" onclick="alert('Dev In Progress')">
|
||||
<span>{{.i18n.copy}}</span>
|
||||
</li>
|
||||
<li onclick="alert('Dev In Progress')">
|
||||
<li class="edit disabled" onclick="alert('Dev In Progress')">
|
||||
<span>{{.i18n.paste}}</span>
|
||||
</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 class="fn-right ft-small">Ctrl-A</span>
|
||||
</li>
|
||||
<li onclick="alert('Dev In Progress')">
|
||||
<li class="edit disabled" onclick="alert('Dev In Progress')">
|
||||
<span>{{.i18n.select_identifier}}</span>
|
||||
</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 class="fn-right ft-small">Ctrl-L</span>
|
||||
</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 class="fn-right ft-small">Ctrl-E</span>
|
||||
</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 class="fn-right ft-small">Shift-Ctrl-Up</span>
|
||||
</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 class="fn-right ft-small">Shift-Ctrl-Down</span>
|
||||
</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 class="fn-right ft-small">Shift-Alt-Up</span>
|
||||
</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 class="fn-right ft-small">Shift-Alt-Down</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -110,23 +128,23 @@
|
|||
<div class="frame">
|
||||
<ul>
|
||||
<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 class="fn-right ft-small">Ctrl-Shift-F</span>
|
||||
</li>
|
||||
<li class="hr"></li>
|
||||
<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 class="fn-right ft-small">Ctrl-\</span>
|
||||
</li>
|
||||
<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 class="fn-right ft-small">Ctrl-B</span>
|
||||
</li>
|
||||
<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 class="fn-right ft-small">Ctrl-I</span>
|
||||
</li>
|
||||
|
@ -137,7 +155,7 @@
|
|||
</li>
|
||||
<li class="hr"></li>
|
||||
<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 class="fn-right ft-small">Ctrl-/</span>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue