Repository navigation
fix(plugins): keep custom editor documents in step with accepted edits #37277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // @vitest-environment happy-dom | ||
|
|
||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| flush, | ||
| mountShell | ||
| } from '../../shared/plugins/frames/plugin-frame-shell-mount.test-fixture' | ||
| import { editor } from './plugin-frame-templates' | ||
|
|
||
| const doc = (version: number, text: string) => ({ | ||
| orca: 1, | ||
| kind: 'evt', | ||
| event: 'editor.document', | ||
| payload: { version, readOnly: false, content: { kind: 'text', text } } | ||
| }) | ||
|
|
||
| function mountEditorTemplate() { | ||
| const html = editor({ id: 'notes', name: 'Notes' }).files['editor/index.html'] | ||
| document.body.innerHTML = html.match(/<body>([\s\S]*?)<script>/)?.[1] ?? '' | ||
| const shell = mountShell('editor') | ||
| // A block scopes the template's top-level consts to this mount. | ||
| window.eval(`{${html.match(/<script>([\s\S]*?)<\/script>/)?.[1] ?? ''}}`) | ||
| const textarea = document.querySelector('textarea')! | ||
| const notice = document.getElementById('notice')! | ||
| const type = (value: string) => { | ||
| textarea.value = value | ||
| textarea.dispatchEvent(new Event('input')) | ||
| } | ||
| return { ...shell, textarea, notice, type } | ||
| } | ||
|
|
||
| describe('editor template', () => { | ||
| it('keeps typing Orca has not accepted when the file changes outside', async () => { | ||
| const { fromHost, textarea, type } = mountEditorTemplate() | ||
| fromHost(doc(1, 'start')) | ||
| await flush() | ||
| expect(textarea.value).toBe('start') | ||
| type('start typed') | ||
| fromHost(doc(2, 'outside')) | ||
| expect(textarea.value).toBe('start typed') | ||
| }) | ||
|
|
||
| it('follows outside changes once its edits are accepted', async () => { | ||
| const { fromHost, textarea, type } = mountEditorTemplate() | ||
| fromHost(doc(1, 'start')) | ||
| await flush() | ||
| type('mine') | ||
| fromHost({ orca: 1, kind: 'res', id: 0, result: null }) | ||
| await flush() | ||
| fromHost(doc(2, 'outside')) | ||
| expect(textarea.value).toBe('outside') | ||
| }) | ||
|
|
||
| it('shows a refused edit and clears it once an edit is accepted', async () => { | ||
| const { fromHost, notice, posted, type } = mountEditorTemplate() | ||
| fromHost(doc(1, 'start')) | ||
| await flush() | ||
| type('mine') | ||
| fromHost({ | ||
| orca: 1, | ||
| kind: 'res', | ||
| id: 0, | ||
| error: { code: 'conflict', message: 'The file changed outside this editor.' } | ||
| }) | ||
| await flush() | ||
| expect(notice.textContent).toBe('Not saved: The file changed outside this editor.') | ||
| fromHost(doc(2, 'outside')) | ||
| type('mine again') | ||
| expect(posted().at(-1)).toMatchObject({ params: { baseVersion: 2 } }) | ||
| fromHost({ orca: 1, kind: 'res', id: 1, result: null }) | ||
| await flush() | ||
| expect(notice.textContent).toBe('') | ||
| }) | ||
|
|
||
| it('lets only the newest input settle dirty and the notice', async () => { | ||
| const { fromHost, textarea, notice, type } = mountEditorTemplate() | ||
| fromHost(doc(1, 'start')) | ||
| await flush() | ||
| type('A') | ||
| type('AB') | ||
| type('A') | ||
| fromHost({ orca: 1, kind: 'res', id: 0, result: null }) | ||
| await flush() | ||
| // The final `A` is still unanswered, so an outside change must not replace it. | ||
| fromHost(doc(2, 'outside')) | ||
| expect(textarea.value).toBe('A') | ||
| fromHost({ orca: 1, kind: 'res', id: 2, error: { code: 'conflict', message: 'Changed.' } }) | ||
| await flush() | ||
| // An older success arriving after a newer refusal keeps the notice. | ||
| fromHost({ orca: 1, kind: 'res', id: 1, result: null }) | ||
| await flush() | ||
| expect(notice.textContent).toBe('Not saved: Changed.') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: stablyai/orca
Length of output: 5228
Script executed:
Repository: stablyai/orca
Length of output: 41823
Script executed:
Repository: stablyai/orca
Length of output: 9919
Script executed:
Repository: stablyai/orca
Length of output: 5295
Answer superseded edits before the replacement edit.
When held edit
cis replaced byd,receiveEditanswersdbeforec. The frame applies both successful responses because their base versions match. The cache can therefore end withc, while the host has appliedd. The accepted-edit path does not bump the version or post a correcting document update.Suggested fix