Add addToHistory parameter to rejectChunk method #4

Closed
baurine wants to merge 1 commit from feat/support-config-addtohistory into main
baurine commented 2024-02-05 11:46:03 +01:00 (Migrated from github.com)

In my case, after rejecting the incoming content, I don't want to see the rejected content again by pressing cmd+z to undo, so I think maybe add the addToHistory parameter to the rejectChunk() is a way. although I don't know whether it's a good idea for everyone. Or do we have a better way to make reject chunk un-revertable?

How I use it:

function rejectChunks(view: EditorView) {
  const chunks = getChunks(view.state)?.chunks || []
  // must traverse from the last to the first
  for (let i = chunks.length - 1; i >= 0; i--) {
    rejectChunk(view, chunks[i].fromB, false)
  }
}
In my case, after rejecting the incoming content, I don't want to see the rejected content again by pressing `cmd+z` to undo, so I think maybe add the `addToHistory` parameter to the `rejectChunk()` is a way. although I don't know whether it's a good idea for everyone. Or do we have a better way to make reject chunk un-revertable? How I use it: ```ts function rejectChunks(view: EditorView) { const chunks = getChunks(view.state)?.chunks || [] // must traverse from the last to the first for (let i = chunks.length - 1; i >= 0; i--) { rejectChunk(view, chunks[i].fromB, false) } } ```
baurine commented 2024-02-05 11:52:09 +01:00 (Migrated from github.com)

Oh, just after submitting the PR, I got a new idea suddenly, maybe we can use the transactionFilter to hook the revert tr, for example:

const rejectChunkFilter = EditorState.transactionFilter.of((tr) => {
  if (tr.isUserEvent('revert')) {
    return {
      ...tr,
      annotations: Transaction.addToHistory.of(false)
    }
  }
  return tr
})

Let me try whether it works.

Update: tried and works fine.

Oh, just after submitting the PR, I got a new idea suddenly, maybe we can use the transactionFilter to hook the `revert` tr, for example: ```ts const rejectChunkFilter = EditorState.transactionFilter.of((tr) => { if (tr.isUserEvent('revert')) { return { ...tr, annotations: Transaction.addToHistory.of(false) } } return tr }) ``` Let me try whether it works. Update: tried and works fine.
marijnh commented 2024-02-12 08:36:36 +01:00 (Migrated from github.com)

Yes, I think a transaction filter (or transaction extender) is a reasonable way to do this, and there's no special feature needed for it.

Yes, I think a transaction filter (or transaction extender) is a reasonable way to do this, and there's no special feature needed for it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/merge!4
No description provided.