Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Plugin, PluginKey, Transaction } from 'prosemirror-state'
import { EditorState, Plugin, PluginKey, Transaction } from 'prosemirror-state'
import type { EditorProps, EditorView } from 'prosemirror-view'

import { getAction, hasAction, setAction, TrackChangesAction } from './actions'
Expand Down Expand Up @@ -141,9 +141,14 @@ export const trackChangesPlugin = (
setAction(createdTr, TrackChangesAction.refreshChanges, true)
}
})

Copilot AI Oct 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining why the changeSet needs to be rebuilt from the current document state before fixing inconsistencies. This will help future maintainers understand the purpose of this rebuild step and its relationship to issue #79.

Suggested change
// Rebuild the changeSet from the current document state if the document has changed.
// This is necessary before fixing inconsistencies to ensure that the changeSet accurately reflects
// the latest document state, preventing issues where inconsistencies are missed or incorrectly handled.
// See issue #79 for details on why this step is required.

Copilot uses AI. Check for mistakes.
const currentChangeSet = createdTr.docChanged
? findChanges(EditorState.create({ doc: createdTr.doc, schema: oldState.schema }))

Copilot AI Oct 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a temporary EditorState just to call findChanges is inefficient and bypasses the normal state lifecycle. Consider refactoring findChanges to accept a document and schema directly, or use the existing state management pattern in the plugin.

Copilot uses AI. Check for mistakes.
: pluginState.changeSet

const changed =
pluginState.changeSet.hasInconsistentData &&
fixInconsistentChanges(pluginState.changeSet, userID, createdTr, oldState.schema)
currentChangeSet.hasInconsistentData &&
fixInconsistentChanges(currentChangeSet, userID, createdTr, oldState.schema)
if (changed) {
log.warn('had to fix inconsistent changes in', createdTr)
}
Expand Down