Bug: Control+t doesn't work

Control+t (transpose-chars) is one of those Emacsisms that work almost everywhere in MacOS. Can it be made to work in Bike also?

Thanks for Bike! I just bought a license. (I thought I should, before requesting an improvement.)

1 Like

FWIW an interim stop-gap:

(e.g. to assign to ^T – for Bike.app – in Keyboard Maestro)

BIKE – transpose 2 characters around cursor.kmmacros.zip (2.5 KB)

Expand disclosure triangle to view JS Source
(() => {
    "use strict";

    ObjC.import("AppKit");

    // Transpose any two characters flanking the cursor,
    // if the selection is not extended.

    // Rob Trew @2022

    // main :: IO ()
    const main = () => {
        const
            bike = Application("Bike"),
            doc = (
                bike.activate(),
                bike.documents.at(0)
            );

        return doc.exists() ? (
            Boolean(doc.selectedText()) ? (
                Left("Selection extended - do nothing.")
            ) : (() => {
                const se = Application("System Events");

                return (
                    $.NSPasteboard.generalPasteboard
                    .clearContents,
                    se.keyCode(124),
                    [1, 2].forEach(() => se.keyCode(
                        123, {
                            using: "shift down"
                        })),
                    se.keystroke("c", {
                        using: "command down"
                    }),
                    delay(0.2),
                    fmapLR(
                        s => 2 === s.length ? (
                            copyText(
                                [...s].reverse().map(
                                    c => (
                                        se.keystroke(c),
                                        c
                                    )
                                )
                                .join("")
                            )
                        ) : (
                            se.keyCode(123),
                            s
                        )
                    )(
                        clipTextLR()
                    )
                );
            })()
        ) : Left("No documents open in Bike");
    };

    // ----------------------- JXA -----------------------

    // clipTextLR :: () -> Either String String
    const clipTextLR = () => {
        // Either a message, (if no clip text is found),
        // or the string contents of the clipboard.
        const
            v = ObjC.unwrap(
                $.NSPasteboard.generalPasteboard
                .stringForType($.NSPasteboardTypeString)
            );

        return Boolean(v) && 0 < v.length ? (
            Right(v)
        ) : Left("No utf8-plain-text found in clipboard.");
    };


    // copyText :: String -> IO String
    const copyText = s => {
        const pb = $.NSPasteboard.generalPasteboard;

        return (
            pb.clearContents,
            pb.setStringForType(
                $(s),
                $.NSPasteboardTypeString
            ),
            s
        );
    };


    // --------------------- GENERIC ---------------------

    // Left :: a -> Either a b
    const Left = x => ({
        type: "Either",
        Left: x
    });


    // Right :: b -> Either a b
    const Right = x => ({
        type: "Either",
        Right: x
    });


    // fmapLR (<$>) :: (a -> b) -> Either a a -> Either a b
    const fmapLR = f => lr =>
        "Left" in lr ? (
            lr
        ) : Right(f(lr.Right));

    return main();
})();
1 Like

Just a note that I’ve added this to my list. Right now my focus is on adding rich text to Bike. After that I plan to work on text input system and expect to add support for transpose then.

This is implemented in Bike 1.7 Preview Bike 1.7 Preview (90) - #26 by jessegrosjean

1 Like