Skip to content

Commit

Permalink
add undo and redo scroll into view when update selection
Browse files Browse the repository at this point in the history
  • Loading branch information
alissa-tung authored Jun 18, 2024
1 parent 0d377ac commit b00d06b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/y-undomanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ class YUndoManagerPluginValue {
const sel = stackItem.meta.get(this)
if (sel) {
const selection = this.syncConf.fromYRange(sel)
view.dispatch(view.state.update({ selection }))
view.dispatch(view.state.update({
selection,
effects: [cmView.EditorView.scrollIntoView(selection)]
}))
this._storeSelection()
}
}
Expand Down Expand Up @@ -122,28 +125,14 @@ export const yUndoManager = cmView.ViewPlugin.fromClass(YUndoManagerPluginValue)
/**
* @type {cmState.StateCommand}
*/
export const undo = ({ state, dispatch }) => {
if (state.facet(yUndoManagerFacet).undo()) {
dispatch(
state.update({
effects: [cmView.EditorView.scrollIntoView(state.selection.main)]
}))
}
return true
}
export const undo = ({ state, dispatch }) =>
state.facet(yUndoManagerFacet).undo() || true

/**
* @type {cmState.StateCommand}
*/
export const redo = ({ state, dispatch }) => {
if (state.facet(yUndoManagerFacet).redo()) {
dispatch(
state.update({
effects: [cmView.EditorView.scrollIntoView(state.selection.main)]
}))
}
return true
}
export const redo = ({ state, dispatch }) =>
state.facet(yUndoManagerFacet).redo() || true

/**
* @param {cmState.EditorState} state
Expand Down

0 comments on commit b00d06b

Please sign in to comment.