1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-31 00:07:48 +02:00

Mobile: Fixes #13193: Fix Markdown toolbar (#13514)

This commit is contained in:
Henry Heino
2025-10-23 02:40:28 -07:00
committed by GitHub
parent c3b4a4b955
commit 918c8830e0
4 changed files with 79 additions and 7 deletions

View File

@@ -701,6 +701,7 @@ packages/app-mobile/components/NoteEditor/ImageEditor/ImageEditor.js
packages/app-mobile/components/NoteEditor/ImageEditor/autosave.js
packages/app-mobile/components/NoteEditor/ImageEditor/isEditableResource.js
packages/app-mobile/components/NoteEditor/ImageEditor/promptRestoreAutosave.js
packages/app-mobile/components/NoteEditor/MarkdownEditor.test.js
packages/app-mobile/components/NoteEditor/MarkdownEditor.js
packages/app-mobile/components/NoteEditor/NoteEditor.test.js
packages/app-mobile/components/NoteEditor/NoteEditor.js

1
.gitignore vendored
View File

@@ -674,6 +674,7 @@ packages/app-mobile/components/NoteEditor/ImageEditor/ImageEditor.js
packages/app-mobile/components/NoteEditor/ImageEditor/autosave.js
packages/app-mobile/components/NoteEditor/ImageEditor/isEditableResource.js
packages/app-mobile/components/NoteEditor/ImageEditor/promptRestoreAutosave.js
packages/app-mobile/components/NoteEditor/MarkdownEditor.test.js
packages/app-mobile/components/NoteEditor/MarkdownEditor.js
packages/app-mobile/components/NoteEditor/NoteEditor.test.js
packages/app-mobile/components/NoteEditor/NoteEditor.js

View File

@@ -0,0 +1,76 @@
import * as React from 'react';
import { describe, it, beforeEach } from '@jest/globals';
import { render, waitFor } from '../../utils/testing/testingLibrary';
import Setting from '@joplin/lib/models/Setting';
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
import TestProviderStack from '../testing/TestProviderStack';
import createMockReduxStore from '../../utils/testing/createMockReduxStore';
import createTestEditorProps from './testing/createTestEditorProps';
import { EditorEvent, EditorEventType } from '@joplin/editor/events';
import { RefObject, useCallback } from 'react';
import { EditorCommandType, EditorControl } from '@joplin/editor/types';
import MarkdownEditor from './MarkdownEditor';
interface WrapperProps {
ref?: RefObject<EditorControl>;
onBodyChange: (newBody: string)=> void;
noteBody: string;
}
const defaultEditorProps = createTestEditorProps();
const testStore = createMockReduxStore();
const WrappedEditor: React.FC<WrapperProps> = (
{
noteBody,
onBodyChange,
ref,
}: WrapperProps,
) => {
const onEvent = useCallback((event: EditorEvent) => {
if (event.kind === EditorEventType.Change) {
onBodyChange(event.value);
}
}, [onBodyChange]);
return <TestProviderStack store={testStore}>
<MarkdownEditor
{...defaultEditorProps}
onEditorEvent={onEvent}
initialText={noteBody}
editorRef={ref ?? defaultEditorProps.editorRef}
/>
</TestProviderStack>;
};
describe('MarkdownEditor', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(0);
await switchClient(0);
Setting.setValue('editor.codeView', true);
});
// Regression test for #13193. This verifies that the editor can be reached
// over IPC.
it('should support the "textBold" command', async () => {
let editorBody = 'test';
const editorRef = React.createRef<EditorControl|null>();
render(<WrappedEditor
ref={editorRef}
noteBody={editorBody}
onBodyChange={newValue => { editorBody = newValue; }}
/>);
// Should mark the command as supported
expect(await editorRef.current.supportsCommand(EditorCommandType.ToggleBolded));
// Command should run
await editorRef.current.execCommand(EditorCommandType.SelectAll);
await editorRef.current.execCommand(EditorCommandType.ToggleBolded);
await waitFor(() => {
expect(editorBody).toBe('**test**');
});
});
});

View File

@@ -61,12 +61,6 @@ const useWebViewSetup = ({
// Since the editor content is included in editorOptions, for large documents,
// creating the initial injected JS is potentially expensive.
afterLoadFinishedJs.current = () => `
if (typeof window.markdownEditorBundle === 'undefined') {
${shim.injectedJs('markdownEditorBundle')};
window.markdownEditorBundle = markdownEditorBundle;
markdownEditorBundle.setUpLogger();
}
if (!window.cm) {
const parentClassName = ${JSON.stringify(editorOptions?.parentElementOrClassName)};
const foundParent = !!parentClassName && document.getElementsByClassName(parentClassName).length > 0;
@@ -94,7 +88,7 @@ const useWebViewSetup = ({
`;
const injectedJavaScript = useMemo(() => `
if (typeof markdownEditorBundle === 'undefined') {
if (typeof window.markdownEditorBundle === 'undefined') {
${shim.injectedJs('markdownEditorBundle')};
window.markdownEditorBundle = markdownEditorBundle;
markdownEditorBundle.setUpLogger();