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
|
// editor commands
|
||||||
for (const name of ['save', 'toggleStyle', 'nextEditor', 'prevEditor']) {
|
for (const name of ['save', 'toggleStyle', 'nextEditor', 'prevEditor']) {
|
||||||
CodeMirror.commands[name] = () => editor[name]();
|
CodeMirror.commands[name] = (...args) => editor[name](...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeMirror convenience commands
|
// CodeMirror convenience commands
|
||||||
|
|
|
@ -201,35 +201,27 @@ function createSectionsEditor(style) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextEditor(cm, cycle = true) {
|
function nextEditor(cm, cycle = true) {
|
||||||
if (!cycle) {
|
if (!cycle && findLast(sections, s => !s.isRemoved()).cm === cm) {
|
||||||
for (const section of sections) {
|
|
||||||
if (section.isRemoved()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (cm === section.cm) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nextPrevEditor(cm, 1);
|
return nextPrevEditor(cm, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prevEditor(cm, cycle = true) {
|
function prevEditor(cm, cycle = true) {
|
||||||
if (!cycle) {
|
if (!cycle && sections.find(s => !s.isRemoved()).cm === cm) {
|
||||||
for (let i = sections.length - 1; i >= 0; i--) {
|
|
||||||
if (sections[i].isRemoved()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (cm === sections[i].cm) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nextPrevEditor(cm, -1);
|
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) {
|
function nextPrevEditor(cm, direction) {
|
||||||
const editors = getEditors();
|
const editors = getEditors();
|
||||||
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
|
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user