mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-12-02 04:17:09 -05:00
Make Alt+ArrowUp and Alt+ArrowDown wrap around
This commit is contained in:
parent
9224ab9d0d
commit
9affdb894f
1 changed files with 16 additions and 17 deletions
|
@ -1,5 +1,15 @@
|
||||||
import { ReceiptType, Unread, BufferType, SERVER_BUFFER } from "./state.js";
|
import { ReceiptType, Unread, BufferType, SERVER_BUFFER } from "./state.js";
|
||||||
|
|
||||||
|
function getSiblingBuffer(buffers, bufID, delta) {
|
||||||
|
var bufList = Array.from(buffers.values());
|
||||||
|
var i = bufList.findIndex((buf) => buf.id === bufID);
|
||||||
|
if (i < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
i = (i + bufList.length + delta) % bufList.length;
|
||||||
|
return bufList[i];
|
||||||
|
}
|
||||||
|
|
||||||
export const keybindings = [
|
export const keybindings = [
|
||||||
{
|
{
|
||||||
key: "h",
|
key: "h",
|
||||||
|
@ -56,15 +66,9 @@ export const keybindings = [
|
||||||
altKey: true,
|
altKey: true,
|
||||||
description: "Jump to the previous buffer",
|
description: "Jump to the previous buffer",
|
||||||
execute: (app) => {
|
execute: (app) => {
|
||||||
var prev = null;
|
var prev = getSiblingBuffer(app.state.buffers, app.state.activeBuffer, -1);
|
||||||
for (var buf of app.state.buffers.values()) {
|
if (prev) {
|
||||||
if (app.state.activeBuffer == buf.id) {
|
app.switchBuffer(prev);
|
||||||
if (prev) {
|
|
||||||
app.switchBuffer(prev);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
prev = buf;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -73,14 +77,9 @@ export const keybindings = [
|
||||||
altKey: true,
|
altKey: true,
|
||||||
description: "Jump to the next buffer",
|
description: "Jump to the next buffer",
|
||||||
execute: (app) => {
|
execute: (app) => {
|
||||||
var found = false;
|
var next = getSiblingBuffer(app.state.buffers, app.state.activeBuffer, 1);
|
||||||
for (var buf of app.state.buffers.values()) {
|
if (next) {
|
||||||
if (found) {
|
app.switchBuffer(next);
|
||||||
app.switchBuffer(buf);
|
|
||||||
break;
|
|
||||||
} else if (app.state.activeBuffer == buf.id) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue