markerikson / joplin-plugin-vscode-style-search

A Joplin plugin that provides a search UI panel patterned after VS Code, with matches per note and per-match hit highlighting
20 stars 2 forks source link

Feature Request: Scroll to Line #3

Open reichemn opened 1 month ago

reichemn commented 1 month ago

Hey,

thanks for your work on the plugin! I saw your Todo-Comment to figure out how to scroll to a specific line.

I never worked on a joplin plugin and don't know the limitions imposed by the joplin api, but I found the code used by joplin to scroll in the editor. Maybe you can adapt this code. This code is used by the joplin own search to scroll to the next result:

let range = findNextOccurrence(state, searchedText)
  if (!range) return false

  dispatch(state.update({
    selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false),
    effects: EditorView.scrollIntoView(range.to)
  }))

This code is used in a "scroll to line"-dialog:

 let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line)))
    let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length)))
    view.dispatch({
      effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, {y: 'center'})],
      selection,
    })
    view.focus()
executed commented 1 week ago

Is there any way we can patch this locally? It always opens the very first line of the note which is crazy. I know that "Note Link" plugin has implemented the scrolling to specific header, but it only scrolls in preview mode and then resets to the beginning of note after couple of seconds due to known Joplin bug.

markerikson commented 1 week ago

I'm very happy to accept PRs to improve this plugin. I'd like to make some improvements to it in general (sorting options, etc). but life is extremely busy right now and I don't have time to work on this myself atm.