CM6 Scroll To Middle?

Is there a way to configure the “scrollIntoView” option in a transaction update to scroll the selection to the middle of the screen rather than the bottom?

Not currently. Would you want the cursor to always be kept in the middle, or only moved there when it hits one of the sides?

I think I would prefer it always to be in the middle if the option is enabled but I could see the argument for both.

I think the best way forward would be to write your own view plugin that does this. Something like…

const centerCursor = ViewPlugin.fromClass(class {
  update(update: ViewUpdate) {
    if (update.transactions.some(tr => tr.scrollIntoView)) {
      let view = update.view
      // (Sync with other DOM read/write phases for efficiency)
      view.requestMeasure({
        read() {
          return {
            cursor: view.coordsAtPos(view.state.selection.main.head),
            scroller: view.scrollDOM.getBoundingClientRect()
          }
        },
        write({cursor, scroller}) {
          if (cursor) {
            let curMid = (cursor.top + cursor.bottom) / 2
            let eltMid = (scroller.top + scroller.bottom) / 2
            if (Math.abs(curMid - eltMid) > 5)
              view.scrollDOM.scrollTop += curMid - eltMid
          }
        }
      })
    }
  }
})

Well that’s legit, thank you!