Skip to content

Commit

Permalink
fix undo and redo scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
alissa-tung authored Jun 17, 2024
1 parent faffa7b commit 0d377ac
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/y-undomanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,28 @@ export const yUndoManager = cmView.ViewPlugin.fromClass(YUndoManagerPluginValue)
/**
* @type {cmState.StateCommand}
*/
export const undo = ({ state, dispatch }) =>
state.facet(yUndoManagerFacet).undo() || true
export const undo = ({ state, dispatch }) => {
if (state.facet(yUndoManagerFacet).undo()) {
dispatch(
state.update({
effects: [cmView.EditorView.scrollIntoView(state.selection.main)]
}))
}
return true
}

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

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

0 comments on commit 0d377ac

Please sign in to comment.