Fix: cycle through editors (#572)
* Fix: cycle through editors * Fix: command is broken
This commit is contained in:
parent
9250d5c624
commit
25fb5acabe
|
@ -230,7 +230,7 @@
|
|||
|
||||
// editor commands
|
||||
for (const name of ['save', 'toggleStyle', 'nextEditor', 'prevEditor']) {
|
||||
CodeMirror.commands[name] = () => editor[name]();
|
||||
CodeMirror.commands[name] = (...args) => editor[name](...args);
|
||||
}
|
||||
|
||||
// CodeMirror convenience commands
|
||||
|
|
|
@ -201,35 +201,27 @@ function createSectionsEditor(style) {
|
|||
}
|
||||
|
||||
function nextEditor(cm, cycle = true) {
|
||||
if (!cycle) {
|
||||
for (const section of sections) {
|
||||
if (section.isRemoved()) {
|
||||
continue;
|
||||
}
|
||||
if (cm === section.cm) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!cycle && findLast(sections, s => !s.isRemoved()).cm === cm) {
|
||||
return;
|
||||
}
|
||||
return nextPrevEditor(cm, 1);
|
||||
}
|
||||
|
||||
function prevEditor(cm, cycle = true) {
|
||||
if (!cycle) {
|
||||
for (let i = sections.length - 1; i >= 0; i--) {
|
||||
if (sections[i].isRemoved()) {
|
||||
continue;
|
||||
}
|
||||
if (cm === sections[i].cm) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!cycle && sections.find(s => !s.isRemoved()).cm === cm) {
|
||||
return;
|
||||
}
|
||||
return nextPrevEditor(cm, -1);
|
||||
}
|
||||
|
||||
function findLast(arr, match) {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
if (match(arr[i])) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nextPrevEditor(cm, direction) {
|
||||
const editors = getEditors();
|
||||
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
|
||||
|
|
Loading…
Reference in New Issue
Block a user