GithubHelp home page GithubHelp logo

kometenstaub / obsidian-vim-reading-view-navigation Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 4.0 131 KB

Allows navigating Obsidian's Reading View with j, k, gg and G

License: MIT License

TypeScript 100.00%
obsidian-md obsidian-plugin

obsidian-vim-reading-view-navigation's Introduction

Obsidian Vim Reading View Navigation

This plugin allows to scroll with j and k in the Reading View.

It also lets you navigate with gg and G to the top or bottom of a note. (When embeds are present, you may need to press G more than once.)

Configuration

The scroll speed can be configured in the settings.

Installation

It can be installed manually or via BRAT. It is not in the community plugins.

Known issues

When the search is open in reading view and edit view is toggled on and off, the search needs to be closed and reopened again for it to work correctly.

Credits

Thank you to @pjeby for the monkey-around library which is used for monkey-patching internal methods.

obsidian-vim-reading-view-navigation's People

Contributors

chrisgrieser avatar kometenstaub avatar zhaoshenzhai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

obsidian-vim-reading-view-navigation's Issues

Use hide and not showsearch, just dedupe

Don’t uninstall and just dedupe. keep a history of IDs and don’t patch again if it matches. Use a set for it.
Uninstall everything onunload.

Monkey-patch hide instead of showSearch because showSearch simply overrides the scope on the leaf, #6. When hide is called, execute it and set again our scope.

I jumps in weird ways, is different than arrow keys

Hey, the movement is weird, it sometimes moves in unpredictable ways and sometimes stuck. Can't you just send arrow keys? I have mapped caplock j,k to arrow keys and it works without any of these problems

thank you

Allow to add other vim keys for navigate

Thank you for this.

You could also enable this:

  • Normal scroll speed for j and k
  • Increased scroll speed with d and u (d to go down and u to go up).

Or at least it allows j and k to be changed to a user-indicated key.

Error frequently thrown in console

Uncaught TypeError: Cannot read properties of null (reading 'hide')
    at around1 (plugin:vim-reading-view-navigation:70:23)
    at eval (plugin:vim-reading-view-navigation:64:56)
    at Array.map (<anonymous>)
    at around (plugin:vim-reading-view-navigation:64:43)
    at eval (plugin:vim-reading-view-navigation:206:13)
    at t.e.tryTrigger (app.js:1:1064472)
    at t.e.trigger (app.js:1:1064405)
    at t.trigger (app.js:1:1841754)
    at t.activeLeafEvents (app.js:1:1827566)
    at s (app.js:1:709926)

Respective line in script:

// node_modules/monkey-around/mjs/index.js
function around(obj, factories) {
  const removers = Object.keys(factories).map((key) => around1(obj, key, factories[key]));
  return removers.length === 1 ? removers[0] : function() {
    removers.forEach((r) => r());
  };
}
function around1(obj, method, createWrapper) {
  const original = obj[method], hadOwn = obj.hasOwnProperty(method); /* 👈 THIS LINE */
  let current = createWrapper(original);
  if (original)
    Object.setPrototypeOf(current, original);

Set scope on leaf

if (leaf.view.getViewType() === 'markdown') {

If leaf.view.scope is null, set the leaf’s scope to our scope.

This will be unset by the search. I only need to hook into the hide method that will be called and then set the leaf scope again to our scope.

That should avoid breaking a lot of things and popping/pushing it at some places.

j/k navigation doesn't work for longer notes

J/K navigation often doesn't work right in longer notes.

  • Long note with many callouts (378 lines):
    • When at the top of the note, j/k don't work at all.
    • When the mouse is used to scroll partially down the note, k scrolls up slightly and j scrolls up by larger amounts; neither scrolls down.
  • Long note without any callouts (270 lines):
    • When at the top, j will scroll down slightly with each keypress (less than a line), but stops being able to scroll 6-ish lines down for me. k works fine.

Obsidian version (and installer version): 0.15.9

I have plenty of other plugins installed and enabled, but since you said you think you knew what the issue was, I haven't gone to test this without any plugins enabled.

Support search in document

  • mutation observer for display style of search/replace element on active-leaf-change
    • only keep it for active leaf and remove it for the old one
  • When change, pop scope and push scope with scope on active leaf
  • Reverse when display style changes again

`j` does not work when scrolled to the top and the note has YAML

Steps to reproduce:

  1. In preview mode, scroll to the top.
  2. Switch to edit mode, and add a valid YAML frontmatter.
  3. Switch back to preview mode.
  4. Press j.
  5. Notice that it does not scroll down.

Observations:

  • Everything works as long as the note either:
    • Does not have a YAML
    • Has a YAML, but scrolled down a bit
  • The getScroll method returns NaN if scrolled to the top. I fixed it to return 0 in that case, but the issue persists.
  • Noticed this issue while working on #2, but the issue persists with a fresh vault and a fresh install of the plugin (that is, without my changes).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.