[Hotkeys] Assigning "longer sequence of the key combinations"

Okay, so the duplication of CTRL+E + CTRL+HOME is necessitated because you cannot go home in Reading mode, correct?
Then I don’t know…do you have Properties set to Visible? (I don’t.) Do you want to look at that if you do have it set to Visible…?

Then…even if you have a top level heading, you cannot (normally) go higher than the top of the editor, below the YAML (but as I said, I have Properties hidden and I’m mostly in Live Preview).
So if you absolutely must go to the very first line, that would be line zero that you can get to in Source Mode.

Using CodeScript Toolkit plugin (as my go-to plugin to make scripts, as I explained in that thread), I created a script that switches to source mode to be able to go to the absolute top possible and then switches to Reading mode (if that’s what’s required or you want editing mode?):

import { App, Plugin } from "obsidian";

const gotoFirstLine = async (app: App): Promise<void> => {
    const leaf = app.workspace.activeLeaf;
    if (!leaf) return;

    // Switch to source mode first
    const viewState = leaf.getViewState();
    viewState.state.mode = "source";
    viewState.state.source = true;
    await leaf.setViewState(viewState);

    // Wait for the state to fully apply
    await new Promise((resolve) => setTimeout(resolve, 100));

    // Get editor and move cursor to line 0
    const editor = leaf.view?.editor;
    if (editor) {
        editor.setCursor({ line: 0, ch: 0 });
    }

    // Switch to reading mode
    viewState.state.mode = "preview";
    await leaf.setViewState(viewState);
};

export class GotofirstlinePlugin extends Plugin {
    async onload() {
        this.addCommand({
            id: "go-to-first-line",
            name: "Go to first line",
            callback: async () => await gotoFirstLine(this.app),
        });
    }
}

// This function will work on both desktop and mobile
export async function invoke(app: App): Promise<void> {
    return gotoFirstLine(app);
}

Save this as Go to First Line.ts in the folder where you will store your CodeScript ts (TypeScript) files.

You can bind a hotkey of your choice to this script:

1 Like