Skip to content

Commit 8121e74

Browse files
committed
Directly export updateOriginalDoc
FEATURE: The state effect used to change the original document in a unified merge view is now available to client code as `updateOriginalDoc`. See https://discuss.codemirror.net/t/using-merge-w-collab/7648
1 parent 7892fa6 commit 8121e74

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,17 @@ to the content it has in the original document.</p>
206206
<dd><p>Get the original document from a unified merge editor's state.</p>
207207
</dd>
208208
<dt id="user-content-originaldocchangeeffect">
209-
<code><strong><a href="#user-content-originaldocchangeeffect">originalDocChangeEffect</a></strong>(<a id="user-content-originaldocchangeeffect^state" href="#user-content-originaldocchangeeffect^state">state</a>: <a href="https://codemirror.net/docs/ref#state.EditorState">EditorState</a>, <a id="user-content-originaldocchangeeffect^changes" href="#user-content-originaldocchangeeffect^changes">changes</a>: <a href="https://codemirror.net/docs/ref#state.ChangeSet">ChangeSet</a>) → <a href="https://codemirror.net/docs/ref#state.StateEffect">StateEffect</a>&lt;any&gt;</code></dt>
209+
<code><strong><a href="#user-content-originaldocchangeeffect">originalDocChangeEffect</a></strong>(<a id="user-content-originaldocchangeeffect^state" href="#user-content-originaldocchangeeffect^state">state</a>: <a href="https://codemirror.net/docs/ref#state.EditorState">EditorState</a>, <a id="user-content-originaldocchangeeffect^changes" href="#user-content-originaldocchangeeffect^changes">changes</a>: <a href="https://codemirror.net/docs/ref#state.ChangeSet">ChangeSet</a>) → <a href="https://codemirror.net/docs/ref#state.StateEffect">StateEffect</a>&lt;{doc: <a href="https://codemirror.net/docs/ref#state.Text">Text</a>, changes: <a href="https://codemirror.net/docs/ref#state.ChangeSet">ChangeSet</a>}&gt;</code></dt>
210210

211211
<dd><p>Create an effect that, when added to a transaction on a unified
212212
merge view, will update the original document that's being compared against.</p>
213213
</dd>
214+
<dt id="user-content-updateoriginaldoc">
215+
<code><strong><a href="#user-content-updateoriginaldoc">updateOriginalDoc</a></strong>: <a href="https://codemirror.net/docs/ref#state.StateEffectType">StateEffectType</a>&lt;{doc: <a href="https://codemirror.net/docs/ref#state.Text">Text</a>, changes: <a href="https://codemirror.net/docs/ref#state.ChangeSet">ChangeSet</a>}&gt;</code></dt>
216+
217+
<dd><p>The state effect used to signal changes in the original doc in a
218+
unified merge view.</p>
219+
</dd>
214220
</dl>
215221
<h3>Chunks</h3>
216222
<dl>

src/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ to communication around the project.
4141

4242
@originalDocChangeEffect
4343

44+
@updateOriginalDoc
45+
4446
### Chunks
4547

4648
@Chunk

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export {getChunks, goToNextChunk, goToPreviousChunk} from "./merge"
44

55
export {MergeConfig, DirectMergeConfig, MergeView} from "./mergeview"
66

7-
export {unifiedMergeView, acceptChunk, rejectChunk, getOriginalDoc, originalDocChangeEffect} from "./unified"
7+
export {unifiedMergeView, acceptChunk, rejectChunk, getOriginalDoc,
8+
originalDocChangeEffect, updateOriginalDoc} from "./unified"
89

910
export {Chunk} from "./chunk"

src/unified.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ export function unifiedMergeView(config: UnifiedMergeConfig) {
7272
]
7373
}
7474

75-
const updateOriginalDoc = StateEffect.define<{doc: Text, changes: ChangeSet}>()
75+
/// The state effect used to signal changes in the original doc in a
76+
/// unified merge view.
77+
export const updateOriginalDoc = StateEffect.define<{doc: Text, changes: ChangeSet}>()
7678

7779
/// Create an effect that, when added to a transaction on a unified
7880
/// merge view, will update the original document that's being compared against.
79-
export function originalDocChangeEffect(state: EditorState, changes: ChangeSet): StateEffect<any> {
81+
export function originalDocChangeEffect(state: EditorState, changes: ChangeSet): StateEffect<{doc: Text, changes: ChangeSet}> {
8082
return updateOriginalDoc.of({doc: changes.apply(state.doc), changes})
8183
}
8284

0 commit comments

Comments
 (0)