Skip to content

Commit 0d2b0f8

Browse files
committed
Convert Editor to CSS modules
1 parent 4697dfb commit 0d2b0f8

File tree

9 files changed

+45
-50
lines changed

9 files changed

+45
-50
lines changed

tests/spec/features/assistance_spec.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
click_on("add a main function")
1818
end
1919

20-
within('.editor') do
21-
expect(editor).to have_line 'println!("Hello, world!")'
22-
end
20+
expect(editor).to have_line 'println!("Hello, world!")'
2321
end
2422

2523
scenario "using an unstable feature offers adding the feature flag" do
@@ -33,9 +31,7 @@
3331
click_on("add `#![feature(abi_avr_interrupt)]`")
3432
end
3533

36-
within('.editor') do
37-
expect(editor).to have_line '#![feature(abi_avr_interrupt)]'
38-
end
34+
expect(editor).to have_line '#![feature(abi_avr_interrupt)]'
3935
end
4036

4137
scenario "using a type that hasn't been imported offers importing it" do
@@ -48,9 +44,7 @@
4844
click_on("use std::collections::HashMap;")
4945
end
5046

51-
within('.editor') do
52-
expect(editor).to have_line 'use std::collections::HashMap;'
53-
end
47+
expect(editor).to have_line 'use std::collections::HashMap;'
5448
end
5549

5650
scenario "triggering a panic offers enabling backtraces" do

tests/spec/features/tools_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
editor.set 'fn main() { [1,2,3,4]; }'
1414
in_tools_menu { click_on("Rustfmt") }
1515

16-
within('.editor') do
17-
expect(editor).to have_line '[1, 2, 3, 4];'
18-
end
16+
expect(editor).to have_line '[1, 2, 3, 4];'
1917
end
2018

2119
scenario "linting code with Clippy" do

tests/spec/support/editor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def initialize(page)
55
end
66

77
def set(text)
8-
page.within('.editor .ace_text-input', visible: :any) do
8+
page.within('.ace_text-input', visible: :any) do
99
page.execute_script <<~JS
1010
window.rustPlayground.setCode(#{text.to_json});
1111
JS
@@ -17,7 +17,7 @@ def has_line?(text)
1717
end
1818

1919
def has_highlighted_text?(text)
20-
page.within('.editor .ace_text-input', visible: :any) do
20+
page.within('.ace_text-input', visible: :any) do
2121
selected = page.evaluate_script <<~JS
2222
(() => {
2323
const editor = document.querySelector('.ace_editor').env.editor;

ui/frontend/AdvancedEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { aceResizeKey } from './selectors';
55
import State from './state';
66
import { AceResizeKey, CommonEditorProps, Crate, Edition, PairCharacters, Position, Selection } from './types';
77

8+
import styles from './Editor.module.css';
9+
810
type Ace = typeof import('ace-builds');
911
type AceEditor = import('ace-builds').Ace.Editor;
1012
type AceCompleter = import('ace-builds').Ace.Completer;
@@ -289,7 +291,7 @@ const AdvancedEditor: React.SFC<AdvancedEditorProps> = props => {
289291
}, []));
290292

291293
return (
292-
<div className="editor-advanced" ref={child} />
294+
<div className={styles.advanced} ref={child} />
293295
);
294296
};
295297

ui/frontend/Editor.module.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.container {
2+
composes: -autoSize from './shared.module.css';
3+
position: relative;
4+
}
5+
6+
.advanced {
7+
composes: -bodyMonospace -autoSize from './shared.module.css';
8+
position: absolute;
9+
}
10+
11+
.simple {
12+
composes: advanced;
13+
border: none;
14+
}

ui/frontend/Editor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import AdvancedEditor from './AdvancedEditor';
66
import { CommonEditorProps, Editor as EditorType, Position, Selection } from './types';
77
import { State } from './reducers';
88

9+
import styles from './Editor.module.css';
10+
911
class CodeByteOffsets {
1012
readonly code: string;
1113
readonly lines: string[];
@@ -61,7 +63,7 @@ class SimpleEditor extends React.PureComponent<CommonEditorProps> {
6163
return (
6264
<textarea
6365
ref={this.trackEditor}
64-
className="editor-simple"
66+
className={styles.simple}
6567
name="editor-simple"
6668
autoCapitalize="none"
6769
autoComplete="off"
@@ -119,7 +121,7 @@ const Editor: React.SFC = () => {
119121
const SelectedEditor = editor === EditorType.Simple ? SimpleEditor : AdvancedEditor;
120122

121123
return (
122-
<div className="editor">
124+
<div className={styles.container}>
123125
<SelectedEditor code={code}
124126
position={position}
125127
selection={selection}

ui/frontend/Playground.module.css

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@
55
padding-bottom: 1em;
66
}
77

8-
.-autoSize {
9-
width: 100%;
10-
min-width: 0;
11-
height: 100%;
12-
min-height: 0;
13-
}
14-
158
.-parent {
16-
composes: -autoSize;
9+
composes: -autoSize from './shared.module.css';
1710
display: grid;
1811
}
1912

@@ -62,11 +55,11 @@ $splitSecondaryDimension: 1fr;
6255
}
6356

6457
.editor {
65-
composes: -autoSize;
58+
composes: -autoSize from './shared.module.css';
6659
border: 4px solid var(--border-color);
6760
border-radius: 4px;
6861
}
6962

7063
.output {
71-
composes: -autoSize;
64+
composes: -autoSize from './shared.module.css';
7265
}

ui/frontend/index.scss

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,6 @@ body {
5454
font-family: 'Source Code Pro', monospace;
5555
}
5656

57-
.editor {
58-
position: relative;
59-
width: 100%;
60-
height: 100%;
61-
62-
&-advanced {
63-
position: absolute;
64-
width: 100%;
65-
height: 100%;
66-
67-
@include body-monospace;
68-
}
69-
70-
&-simple {
71-
position: absolute;
72-
width: 100%;
73-
height: 100%;
74-
75-
border: none;
76-
@include body-monospace;
77-
}
78-
}
79-
8057
.output {
8158
$current-tab: #f9ffff;
8259
$background-tab: desaturate($current-tab, 100%);

ui/frontend/shared.module.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
.-bodyMonospace {
2+
/* http://code.stephenmorley.org/html-and-css/fixing-browsers-broken-monospace-font-handling/
3+
* ACE uses Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace;
4+
*/
5+
font-family: 'Source Code Pro', monospace;
6+
font-size: 0.9em;
7+
}
8+
9+
.-autoSize {
10+
width: 100%;
11+
min-width: 0;
12+
height: 100%;
13+
min-height: 0;
14+
}
15+
116
.-buttonReset {
217
padding: 0;
318
border: none;

0 commit comments

Comments
 (0)