Skip to content

Commit

Permalink
chore: add cm placeholder text (#33635)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Nov 16, 2024
1 parent 5080213 commit a980214
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions packages/recorder/src/recorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CallLogView } from './callLog';
import './recorder.css';
import { asLocator } from '@isomorphic/locatorGenerators';
import { toggleTheme } from '@web/theme';
import { copy } from '@web/uiUtils';
import { copy, useSetting } from '@web/uiUtils';
import yaml from 'yaml';
import { parseAriaKey } from '@isomorphic/ariaSnapshot';
import type { AriaKeyError, ParsedYaml } from '@isomorphic/ariaSnapshot';
Expand All @@ -47,7 +47,7 @@ export const Recorder: React.FC<RecorderProps> = ({
}) => {
const [selectedFileId, setSelectedFileId] = React.useState<string | undefined>();
const [runningFileId, setRunningFileId] = React.useState<string | undefined>();
const [selectedTab, setSelectedTab] = React.useState<string>('log');
const [selectedTab, setSelectedTab] = useSetting<string>('recorderPropertiesTab', 'log');
const [ariaSnapshot, setAriaSnapshot] = React.useState<string | undefined>();
const [ariaSnapshotErrors, setAriaSnapshotErrors] = React.useState<SourceHighlight[]>();

Expand Down Expand Up @@ -189,7 +189,7 @@ export const Recorder: React.FC<RecorderProps> = ({
{
id: 'locator',
title: 'Locator',
render: () => <CodeMirrorWrapper text={locator} language={source.language} focusOnChange={true} onChange={onEditorChange} wrapLines={true} />
render: () => <CodeMirrorWrapper text={locator} placeholder='Type locator to inspect' language={source.language} focusOnChange={true} onChange={onEditorChange} wrapLines={true} />
},
{
id: 'log',
Expand All @@ -198,8 +198,8 @@ export const Recorder: React.FC<RecorderProps> = ({
},
{
id: 'aria',
title: 'Aria snapshot',
render: () => <CodeMirrorWrapper text={ariaSnapshot || ''} language={'yaml'} onChange={onAriaEditorChange} highlight={ariaSnapshotErrors} wrapLines={true} />
title: 'Aria',
render: () => <CodeMirrorWrapper text={ariaSnapshot || ''} placeholder='Type aria template to match' language={'yaml'} onChange={onAriaEditorChange} highlight={ariaSnapshotErrors} wrapLines={true} />
},
]}
selectedTab={selectedTab}
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/codeMirrorModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/python/python';
import 'codemirror/mode/clike/clike';
import 'codemirror/mode/markdown/markdown';
import 'codemirror/addon/display/placeholder';
import 'codemirror/addon/mode/simple';
import 'codemirror/mode/yaml/yaml';

Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/components/codeMirrorWrapper.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,7 @@ body.dark-mode .CodeMirror span.cm-type {
text-decoration-color: var(--vscode-errorForeground);
text-decoration-style: wavy;
}

.CodeMirror-placeholder {
color: var(--vscode-input-placeholderForeground) !important;
}
8 changes: 6 additions & 2 deletions packages/web/src/components/codeMirrorWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface SourceProps {
wrapLines?: boolean;
onChange?: (text: string) => void;
dataTestId?: string;
placeholder?: string;
}

export const CodeMirrorWrapper: React.FC<SourceProps> = ({
Expand All @@ -62,6 +63,7 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
wrapLines,
onChange,
dataTestId,
placeholder,
}) => {
const [measure, codemirrorElement] = useMeasure<HTMLDivElement>();
const [modulePromise] = React.useState<Promise<CodeMirror>>(import('./codeMirrorModule').then(m => m.default));
Expand Down Expand Up @@ -89,7 +91,8 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
&& mode === codemirrorRef.current.cm.getOption('mode')
&& !!readOnly === codemirrorRef.current.cm.getOption('readOnly')
&& lineNumbers === codemirrorRef.current.cm.getOption('lineNumbers')
&& wrapLines === codemirrorRef.current.cm.getOption('lineWrapping')) {
&& wrapLines === codemirrorRef.current.cm.getOption('lineWrapping')
&& placeholder === codemirrorRef.current.cm.getOption('placeholder')) {
// No need to re-create codemirror.
return;
}
Expand All @@ -102,14 +105,15 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
readOnly: !!readOnly,
lineNumbers,
lineWrapping: wrapLines,
placeholder,
});
codemirrorRef.current = { cm };
if (isFocused)
cm.focus();
setCodemirror(cm);
return cm;
})();
}, [modulePromise, codemirror, codemirrorElement, language, mimeType, linkify, lineNumbers, wrapLines, readOnly, isFocused]);
}, [modulePromise, codemirror, codemirrorElement, language, mimeType, linkify, lineNumbers, wrapLines, readOnly, isFocused, placeholder]);

React.useEffect(() => {
if (codemirrorRef.current)
Expand Down
6 changes: 3 additions & 3 deletions tests/library/inspector/cli-codegen-aria.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test.describe(() => {
await recorder.page.click('x-pw-tool-item.pick-locator');
await recorder.page.hover('button');
await recorder.trustedClick();
await recorder.recorderPage.getByRole('tab', { name: 'Aria snapshot' }).click();
await recorder.recorderPage.getByRole('tab', { name: 'Aria' }).click();
await expect(recorder.recorderPage.locator('.tab-aria .CodeMirror')).toMatchAriaSnapshot(`
- textbox
- text: '- button "Submit"'
Expand All @@ -88,7 +88,7 @@ test.describe(() => {
await recorder.page.click('x-pw-tool-item.pick-locator');
await submitButton.hover();
await recorder.trustedClick();
await recorder.recorderPage.getByRole('tab', { name: 'Aria snapshot' }).click();
await recorder.recorderPage.getByRole('tab', { name: 'Aria' }).click();
await expect(recorder.recorderPage.locator('.tab-aria .CodeMirror')).toMatchAriaSnapshot(`
- text: '- button "Submit"'
`);
Expand Down Expand Up @@ -131,7 +131,7 @@ test.describe(() => {
await submitButton.hover();
await recorder.trustedClick();

await recorder.recorderPage.getByRole('tab', { name: 'Aria snapshot' }).click();
await recorder.recorderPage.getByRole('tab', { name: 'Aria' }).click();
await expect(recorder.recorderPage.locator('.tab-aria .CodeMirror')).toMatchAriaSnapshot(`
- text: '- button "Submit"'
`);
Expand Down

0 comments on commit a980214

Please sign in to comment.