mirror of https://github.com/laurent22/joplin.git
Desktop: Rich Text Editor: Fix editor content not updated in some cases when switching notes (#12084)
parent
527627b8bb
commit
fd486e298a
|
@ -1017,6 +1017,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
const lastNoteIdRef = useRef(props.noteId);
|
||||
useEffect(() => {
|
||||
if (!editor) return () => {};
|
||||
|
||||
|
@ -1030,7 +1031,10 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
|
|||
const loadContent = async () => {
|
||||
const resourcesEqual = resourceInfosEqual(lastOnChangeEventInfo.current.resourceInfos, props.resourceInfos);
|
||||
|
||||
if (lastOnChangeEventInfo.current.content !== props.content || !resourcesEqual) {
|
||||
// Use nextOnChangeEventInfo's noteId -- lastOnChangeEventInfo can be slightly out-of-date.
|
||||
const differentNoteId = lastNoteIdRef.current !== props.noteId;
|
||||
const differentContent = lastOnChangeEventInfo.current.content !== props.content;
|
||||
if (differentNoteId || differentContent || !resourcesEqual) {
|
||||
const result = await props.markupToHtml(
|
||||
props.contentMarkupLanguage,
|
||||
props.content,
|
||||
|
@ -1053,6 +1057,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
|
|||
const offsetBookmarkId = 2;
|
||||
const bookmark = editor.selection.getBookmark(offsetBookmarkId);
|
||||
editor.setContent(awfulInitHack(result.html));
|
||||
lastNoteIdRef.current = props.noteId;
|
||||
|
||||
if (lastOnChangeEventInfo.current.contentKey !== props.contentKey) {
|
||||
// Need to clear UndoManager to avoid this problem:
|
||||
|
@ -1101,7 +1106,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
|
|||
cancelled = true;
|
||||
};
|
||||
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
|
||||
}, [editor, props.themeId, props.scrollbarSize, props.markupToHtml, props.allAssets, props.content, props.resourceInfos, props.contentKey, props.contentMarkupLanguage, props.whiteBackgroundNoteRendering]);
|
||||
}, [editor, props.noteId, props.themeId, props.scrollbarSize, props.markupToHtml, props.allAssets, props.content, props.resourceInfos, props.contentKey, props.contentMarkupLanguage, props.whiteBackgroundNoteRendering]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) return () => {};
|
||||
|
|
|
@ -80,7 +80,11 @@ export default class NoteEditorPage {
|
|||
// We use frameLocator(':scope') to convert the richTextEditor Locator into
|
||||
// a FrameLocator. (:scope selects the locator itself).
|
||||
// https://playwright.dev/docs/api/class-framelocator
|
||||
return this.richTextEditor.frameLocator(':scope');
|
||||
return this.richTextEditor.contentFrame();
|
||||
}
|
||||
|
||||
public getRichTextEditorBody() {
|
||||
return this.richTextEditor.contentFrame().locator('body');
|
||||
}
|
||||
|
||||
public focusCodeMirrorEditor() {
|
||||
|
|
|
@ -212,5 +212,33 @@ test.describe('richTextEditor', () => {
|
|||
await expect(editor.noteTitleInput).not.toBeFocused();
|
||||
await expect(editor.richTextEditor).toBeFocused();
|
||||
});
|
||||
|
||||
test('note should have correct content even if opened quickly after last edit', async ({ mainWindow }) => {
|
||||
const mainScreen = await new MainScreen(mainWindow).setup();
|
||||
await mainScreen.createNewNote('Test 1');
|
||||
await mainScreen.createNewNote('Test 2');
|
||||
const test1Header = mainScreen.noteList.getNoteItemByTitle('Test 1');
|
||||
const test2Header = mainScreen.noteList.getNoteItemByTitle('Test 2');
|
||||
|
||||
const editor = mainScreen.noteEditor;
|
||||
await editor.toggleEditorsButton.click();
|
||||
await editor.richTextEditor.waitFor();
|
||||
|
||||
const editorBody = editor.getRichTextEditorBody();
|
||||
const setEditorText = async (targetText: string) => {
|
||||
await editorBody.pressSequentially(targetText);
|
||||
await expect(editorBody).toHaveText(targetText);
|
||||
};
|
||||
|
||||
await test1Header.click();
|
||||
await expect(editorBody).toHaveText('');
|
||||
await setEditorText('Test 1');
|
||||
|
||||
await test2Header.click();
|
||||
// Previously, after switching to note 2, the "Test 1" text would remain present in the
|
||||
// editor.
|
||||
await expect(editorBody).toHaveText('');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue