A pair of macros for Jesse Grosjean's new Bike Outliner:
Hog Bay Software – Bike: Tool for thought
BikeJumpToNextOrPrevEmptyLine.kmmacros (10.0 KB)
-
⌥⌘ ↓
– jump to NEXT empty line -
⌥⌘ ↑
– jump to PREVIOUS empty line
Expand disclosure triangle to view JS Source
(() => {
"use strict";
// BIKE – Select next (or previous) empty line.
// Rob Trew @2022
// Ver 0.03
// JavaScript for Automation
// Test in Script Editor with language selector at
// top left set to JavaScript
// ---------------- DIRECTION OPTION -----------------
// To jump to PREVIOUS blank line,
// edit the value of `directionDown` to false.
const directionDown = true;
// main :: IO ()
// eslint-disable-next-line max-lines-per-function
const main = () => {
const
bike = Application("Bike"),
doc = bike.documents.at(0);
return doc.exists() ? (() => {
const
// IDs paired with names
rows = doc.rows.where({
visible: true
}),
idNames = zip(
rows.id()
)(
rows.name()
),
// Position of selected line
selectedID = doc.selectionRow.id(),
selnIndex = idNames.findIndex(
ab => selectedID === ab[0]
),
// Offset of first blank in remaining or
// preceding lines.
nextIndex = (
directionDown ? (
idNames.slice(1 + selnIndex)
) : (
idNames.slice(0, selnIndex)
.reverse()
)
)
.findIndex(ab => "" === ab[1]);
bike.activate();
// First following blank line selected (if any)
return -1 !== nextIndex ? (
doc.select({
at: rows.at(
(
(x, y) => directionDown ? (
x + y
) : x - y
)(selnIndex, 1 + nextIndex)
)
}),
"Selected"
) : (
Object.assign(
Application.currentApplication(), {
includeStandardAdditions: true
}
).beep(),
`No more blank rows visible in ${doc.name()}`
);
})() : "No document open in Bike.";
};
// --------------------- GENERIC ---------------------
// https://github.com/RobTrew/prelude-jxa
// zip :: [a] -> [b] -> [(a, b)]
const zip = xs =>
// The paired members of xs and ys, up to
// the length of the shorter of the two lists.
ys => Array.from({
length: Math.min(xs.length, ys.length)
}, (_, i) => [xs[i], ys[i]]);
// MAIN ---
return main();
})();