Skip to content

Commit

Permalink
Allow an initial scroll position to be passed to an editor view
Browse files Browse the repository at this point in the history
FEATURE: The new `scrollTo` option to `EditorView` allows an initial scroll position
to be provided.
  • Loading branch information
marijnh committed Nov 3, 2023
1 parent b954fa2 commit 86f2cd1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/editorview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export interface EditorViewConfig extends EditorStateConfig {
/// not this option, the editor will automatically look up a root
/// from the parent.
root?: Document | ShadowRoot,
/// Pass an effect created with
/// [`EditorView.scrollIntoView`](#view.EditorView^scrollIntoView)
/// here to set an initial scroll position.
scrollTo?: StateEffect<any>,
/// Override the way transactions are
/// [dispatched](#view.EditorView.dispatch) for this editor view.
/// Your implementation, if provided, should probably call the
Expand Down Expand Up @@ -193,6 +197,8 @@ export class EditorView {
this._root = (config.root || getRoot(config.parent) || document) as DocumentOrShadowRoot

this.viewState = new ViewState(config.state || EditorState.create(config))
if (config.scrollTo && config.scrollTo.is(scrollIntoView))
this.viewState.scrollTarget = config.scrollTo.value
this.plugins = this.state.facet(viewPlugin).map(spec => new PluginInstance(spec))
for (let plugin of this.plugins) plugin.update(this)
this.observer = new DOMObserver(this)
Expand Down

0 comments on commit 86f2cd1

Please sign in to comment.