Skip to content

Commit 2a00ca8

Browse files
committed
cherry-pick(#33635): chore: add cm placeholder text
1 parent 0e64340 commit 2a00ca8

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

packages/recorder/src/recorder.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { CallLogView } from './callLog';
2727
import './recorder.css';
2828
import { asLocator } from '@isomorphic/locatorGenerators';
2929
import { toggleTheme } from '@web/theme';
30-
import { copy } from '@web/uiUtils';
30+
import { copy, useSetting } from '@web/uiUtils';
3131
import yaml from 'yaml';
3232
import { parseAriaKey } from '@isomorphic/ariaSnapshot';
3333
import type { AriaKeyError, ParsedYaml } from '@isomorphic/ariaSnapshot';
@@ -47,7 +47,7 @@ export const Recorder: React.FC<RecorderProps> = ({
4747
}) => {
4848
const [selectedFileId, setSelectedFileId] = React.useState<string | undefined>();
4949
const [runningFileId, setRunningFileId] = React.useState<string | undefined>();
50-
const [selectedTab, setSelectedTab] = React.useState<string>('log');
50+
const [selectedTab, setSelectedTab] = useSetting<string>('recorderPropertiesTab', 'log');
5151
const [ariaSnapshot, setAriaSnapshot] = React.useState<string | undefined>();
5252
const [ariaSnapshotErrors, setAriaSnapshotErrors] = React.useState<SourceHighlight[]>();
5353

@@ -189,7 +189,7 @@ export const Recorder: React.FC<RecorderProps> = ({
189189
{
190190
id: 'locator',
191191
title: 'Locator',
192-
render: () => <CodeMirrorWrapper text={locator} language={source.language} focusOnChange={true} onChange={onEditorChange} wrapLines={true} />
192+
render: () => <CodeMirrorWrapper text={locator} placeholder='Type locator to inspect' language={source.language} focusOnChange={true} onChange={onEditorChange} wrapLines={true} />
193193
},
194194
{
195195
id: 'log',
@@ -198,8 +198,8 @@ export const Recorder: React.FC<RecorderProps> = ({
198198
},
199199
{
200200
id: 'aria',
201-
title: 'Aria snapshot',
202-
render: () => <CodeMirrorWrapper text={ariaSnapshot || ''} language={'yaml'} onChange={onAriaEditorChange} highlight={ariaSnapshotErrors} wrapLines={true} />
201+
title: 'Aria',
202+
render: () => <CodeMirrorWrapper text={ariaSnapshot || ''} placeholder='Type aria template to match' language={'yaml'} onChange={onAriaEditorChange} highlight={ariaSnapshotErrors} wrapLines={true} />
203203
},
204204
]}
205205
selectedTab={selectedTab}

packages/web/src/components/codeMirrorModule.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'codemirror/mode/javascript/javascript';
2424
import 'codemirror/mode/python/python';
2525
import 'codemirror/mode/clike/clike';
2626
import 'codemirror/mode/markdown/markdown';
27+
import 'codemirror/addon/display/placeholder';
2728
import 'codemirror/addon/mode/simple';
2829
import 'codemirror/mode/yaml/yaml';
2930

packages/web/src/components/codeMirrorWrapper.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,7 @@ body.dark-mode .CodeMirror span.cm-type {
181181
text-decoration-color: var(--vscode-errorForeground);
182182
text-decoration-style: wavy;
183183
}
184+
185+
.CodeMirror-placeholder {
186+
color: var(--vscode-input-placeholderForeground) !important;
187+
}

packages/web/src/components/codeMirrorWrapper.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface SourceProps {
4646
wrapLines?: boolean;
4747
onChange?: (text: string) => void;
4848
dataTestId?: string;
49+
placeholder?: string;
4950
}
5051

5152
export const CodeMirrorWrapper: React.FC<SourceProps> = ({
@@ -62,6 +63,7 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
6263
wrapLines,
6364
onChange,
6465
dataTestId,
66+
placeholder,
6567
}) => {
6668
const [measure, codemirrorElement] = useMeasure<HTMLDivElement>();
6769
const [modulePromise] = React.useState<Promise<CodeMirror>>(import('./codeMirrorModule').then(m => m.default));
@@ -89,7 +91,8 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
8991
&& mode === codemirrorRef.current.cm.getOption('mode')
9092
&& !!readOnly === codemirrorRef.current.cm.getOption('readOnly')
9193
&& lineNumbers === codemirrorRef.current.cm.getOption('lineNumbers')
92-
&& wrapLines === codemirrorRef.current.cm.getOption('lineWrapping')) {
94+
&& wrapLines === codemirrorRef.current.cm.getOption('lineWrapping')
95+
&& placeholder === codemirrorRef.current.cm.getOption('placeholder')) {
9396
// No need to re-create codemirror.
9497
return;
9598
}
@@ -102,14 +105,15 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
102105
readOnly: !!readOnly,
103106
lineNumbers,
104107
lineWrapping: wrapLines,
108+
placeholder,
105109
});
106110
codemirrorRef.current = { cm };
107111
if (isFocused)
108112
cm.focus();
109113
setCodemirror(cm);
110114
return cm;
111115
})();
112-
}, [modulePromise, codemirror, codemirrorElement, language, mimeType, linkify, lineNumbers, wrapLines, readOnly, isFocused]);
116+
}, [modulePromise, codemirror, codemirrorElement, language, mimeType, linkify, lineNumbers, wrapLines, readOnly, isFocused, placeholder]);
113117

114118
React.useEffect(() => {
115119
if (codemirrorRef.current)

tests/library/inspector/cli-codegen-aria.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test.describe(() => {
6767
await recorder.page.click('x-pw-tool-item.pick-locator');
6868
await recorder.page.hover('button');
6969
await recorder.trustedClick();
70-
await recorder.recorderPage.getByRole('tab', { name: 'Aria snapshot' }).click();
70+
await recorder.recorderPage.getByRole('tab', { name: 'Aria' }).click();
7171
await expect(recorder.recorderPage.locator('.tab-aria .CodeMirror')).toMatchAriaSnapshot(`
7272
- textbox
7373
- text: '- button "Submit"'
@@ -88,7 +88,7 @@ test.describe(() => {
8888
await recorder.page.click('x-pw-tool-item.pick-locator');
8989
await submitButton.hover();
9090
await recorder.trustedClick();
91-
await recorder.recorderPage.getByRole('tab', { name: 'Aria snapshot' }).click();
91+
await recorder.recorderPage.getByRole('tab', { name: 'Aria' }).click();
9292
await expect(recorder.recorderPage.locator('.tab-aria .CodeMirror')).toMatchAriaSnapshot(`
9393
- text: '- button "Submit"'
9494
`);
@@ -131,7 +131,7 @@ test.describe(() => {
131131
await submitButton.hover();
132132
await recorder.trustedClick();
133133

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

0 commit comments

Comments
 (0)