Skip to content

Commit 5f97df3

Browse files
committed
Use react-ace
1 parent 4490bef commit 5f97df3

File tree

6 files changed

+114
-123
lines changed

6 files changed

+114
-123
lines changed

package-lock.json

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"fluent-syntax": "0.10.0",
1414
"intl-pluralrules": "^0.2.1",
1515
"react": "^16.6.3",
16+
"react-ace": "^6.3.2",
1617
"react-dom": "^16.6.3"
1718
},
1819
"scripts": {

public/editor.css

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,108 @@
11
:root {
2-
--code-id-color: #28afb0;
3-
--code-variable-color: #7b287d;
4-
--code-string-color: #4357ad;
5-
--code-comment-color: #999;
6-
--code-keyword-color: #96adc8;
7-
--code-function-color: #0470e2;
8-
--code-error-color: #d14;
2+
--code-id-color: #28afb0;
3+
--code-variable-color: #7b287d;
4+
--code-string-color: #4357ad;
5+
--code-comment-color: #999;
6+
--code-keyword-color: #96adc8;
7+
--code-function-color: #0470e2;
8+
--code-error-color: #d14;
99
}
1010

11-
code {
12-
background-color: var(--indent-bg-color);
13-
white-space: pre;
14-
display: block;
15-
overflow: auto;
16-
padding: 1rem;
11+
.example-editor {
12+
background-color: var(--indent-bg-color);
13+
padding-top: 1.5rem;
1714
}
1815

19-
code.ace-fluent .ace_cursor {
16+
.example-editor .ace_editor {
17+
line-height: 1.2rem !important;
18+
}
19+
20+
.example-editor .ace_editor .ace_cursor {
2021
color: var(--main-accent-lighter-color);
2122
}
2223

23-
code.ace-fluent .ace_hidden-cursors .ace_cursor {
24+
.example-editor .ace_editor .ace_hidden-cursors .ace_cursor {
2425
color: transparent;
2526
}
2627

27-
code.ace-fluent .ace_gutter {
28+
.example-editor .ace_editor .ace_gutter {
2829
width: 1rem;
2930
background-color: transparent;
3031
}
3132

32-
code.ace-fluent .ace_gutter-active-line {
33+
.example-editor .ace_editor .ace_gutter-active-line {
3334
background-color: transparent;
3435
}
3536

36-
code.ace-fluent .ace_comment {
37+
.example-editor .ace_editor .ace_comment {
3738
color: var(--code-comment-color);
3839
font-style: italic;
3940
}
4041

41-
code.ace-fluent .ace_section {
42+
.example-editor .ace_editor .ace_section {
4243
color: #666;
4344
}
4445

45-
code.ace-fluent .ace_message {
46+
.example-editor .ace_editor .ace_message {
4647
color: var(--code-id-color);
4748
font-weight: normal;
4849
}
4950

50-
code.ace-fluent .ace_string {
51+
.example-editor .ace_editor .ace_string {
5152
color: var(--code-string-color);
5253
}
5354

54-
code.ace-fluent .ace_number {
55+
.example-editor .ace_editor .ace_number {
5556
color: var(--code-keyword-color);
5657
}
5758

58-
code.ace-fluent .ace_symbol {
59+
.example-editor .ace_editor .ace_symbol {
5960
color: var(--code-keyword-color);
6061
}
6162

62-
code.ace-fluent .ace_variable {
63+
.example-editor .ace_editor .ace_variable {
6364
color: var(--code-variable-color);
6465
}
6566

66-
code.ace-fluent .ace_function {
67+
.example-editor .ace_editor .ace_function {
6768
color: var(--code-function-color);
6869
}
6970

70-
code.ace-fluent .ace_invalid {
71+
.example-editor .ace_editor .ace_invalid {
7172
background-color: #ffe5e5;
7273
color: red;
7374
}
7475

75-
code.ace-fluent .ace_marker-layer .ace_selection {
76+
.example-editor .ace_editor .ace_marker-layer .ace_selection {
7677
background: rgb(181, 213, 255);
7778
}
7879

79-
code.ace-fluent.ace_multiselect .ace_selection.ace_start {
80+
.example-editor .ace_editor .ace_multiselect .ace_selection.ace_start {
8081
box-shadow: 0 0 3px 0px white;
8182
}
8283

83-
code.ace-fluent.ace_nobold .ace_line > span {
84+
.example-editor .ace_editor.ace_nobold .ace_line > span {
8485
font-weight: normal !important;
8586
}
8687

87-
code.ace-fluent .ace_marker-layer .ace_step {
88+
.example-editor .ace_editor .ace_marker-layer .ace_step {
8889
background: rgb(252, 255, 0);
8990
}
9091

91-
code.ace-fluent .ace_marker-layer .ace_stack {
92+
.example-editor .ace_editor .ace_marker-layer .ace_stack {
9293
background: rgb(164, 229, 101);
9394
}
9495

95-
code.ace-fluent .ace_marker-layer .ace_bracket {
96+
.example-editor .ace_editor .ace_marker-layer .ace_bracket {
9697
margin: -1px 0 0 -1px;
9798
border: 1px solid rgb(192, 192, 192);
9899
}
99100

100-
code.ace-fluent .ace_marker-layer .ace_selected-word {
101+
.example-editor .ace_editor .ace_marker-layer .ace_selected-word {
101102
background: rgb(250, 250, 255);
102103
border: 1px solid rgb(200, 200, 250);
103104
}
104105

105-
code.ace-fluent .ace_error {
106+
.example-editor .ace_editor .ace_error {
106107
background: #ffa5a5 !important;
107108
}

public/fluent.css

-10
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ main > ul > li > p > a:hover {
174174
color: var(--main-accent-darker-color);
175175
}
176176

177-
.code {
178-
background-color: var(--indent-bg-color);
179-
padding-top: 1.5rem;
180-
}
181-
182-
.code > code {
183-
height: 8rem;
184-
line-height: 1.2rem !important;
185-
}
186-
187177
main > aside > .variables {
188178
border-top: 1px solid #ddd;
189179
border-bottom: 1px solid var(--main-accent-color);

src/editor.js

+43-72
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,51 @@
1-
// vim: ts=4 et sts=4 sw=4
2-
3-
import React, { Component } from 'react';
1+
import React from 'react';
2+
import AceEditor from 'react-ace';
43

54
import brace from 'brace';
65
import 'brace/mode/json';
76

87
import './editor-mode-fluent';
98
import './editor-theme-fluent';
109

11-
class Editor extends Component {
12-
componentWillReceiveProps(nextProps) {
13-
const { annotations } = nextProps;
14-
this.editor.getSession().setAnnotations(annotations);
15-
}
16-
17-
componentDidMount(){
18-
const {
19-
mode, gutter = "true", fontSize = 14, value, annotations, onChange
20-
} = this.props;
21-
22-
this.editor = brace.edit(this.root);
23-
24-
this.editor.setValue(value);
25-
this.editor.getSession().setAnnotations(annotations);
26-
this.editor.clearSelection();
27-
this.editor.gotoLine(0);
28-
this.editor.on('change', () => onChange(this.editor.getValue()));
29-
30-
this.editor.setOptions({
31-
selectionStyle: 'text',
32-
highlightActiveLine: false,
33-
highlightSelectedWord: false,
34-
readOnly: false,
35-
cursorStyle: 'ace',
36-
mergeUndoDeltas: false,
37-
behavioursEnabled: false,
38-
wrapBehavioursEnabled: false,
39-
autoScrollEditorIntoView: false,
40-
41-
// renderer options
42-
hScrollBarAlwaysVisible: false,
43-
vScrollBarAlwaysVisible: false,
44-
highlightGutterLine: true,
45-
animatedScroll: false,
46-
showInvisibles: false,
47-
showPrintMargin: false,
48-
printMarginColumn: false,
49-
printMargin: false,
50-
fadeFoldWidgets: false,
51-
showFoldWidgets: false,
52-
showLineNumbers: false,
53-
showGutter: gutter,
54-
displayIndentGuides: false,
55-
fontSize,
56-
scrollPastEnd: false,
57-
fixedWidthGutter: false,
58-
theme: `ace/theme/fluent`
59-
});
60-
61-
this.editor.getSession().setOptions({
62-
firstLineNumber: 1,
63-
useWorker: false,
64-
useSoftTabs: true,
65-
tabSize: 4,
66-
mode: `ace/mode/${mode}`
67-
});
68-
69-
}
70-
71-
render() {
72-
return (
73-
<div className="code">
74-
<code ref={elem => this.root = elem}></code>
75-
</div>
76-
);
77-
}
10+
// https://github.com/ajaxorg/ace/wiki/Configuring-Ace
11+
const ACE_OPTIONS = {
12+
// Editor options.
13+
selectionStyle: 'text',
14+
highlightActiveLine: false,
15+
highlightSelectedWord: false,
16+
cursorStyle: 'ace',
17+
mergeUndoDeltas: false,
18+
behavioursEnabled: false,
19+
wrapBehavioursEnabled: false,
20+
autoScrollEditorIntoView: false,
21+
22+
// Renderer options.
23+
hScrollBarAlwaysVisible: false,
24+
vScrollBarAlwaysVisible: false,
25+
highlightGutterLine: true,
26+
animatedScroll: false,
27+
showInvisibles: false,
28+
showPrintMargin: false,
29+
printMarginColumn: false,
30+
printMargin: false,
31+
fadeFoldWidgets: false,
32+
showFoldWidgets: false,
33+
showLineNumbers: false,
34+
displayIndentGuides: false,
35+
scrollPastEnd: false,
36+
fixedWidthGutter: false,
37+
};
38+
39+
export default
40+
function Editor(props) {
41+
return <AceEditor
42+
mode="fluent"
43+
theme="fluent"
44+
fontSize={14}
45+
width="auto"
46+
setOptions={ACE_OPTIONS}
47+
debounceChangePeriod={200}
48+
onLoad={editor => editor.gotoLine(0)}
49+
{...props}
50+
/>;
7851
}
79-
80-
export default Editor;

src/example.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ export default class Example extends Component {
105105

106106
return (
107107
<Fragment>
108-
<Editor
109-
className="editor"
110-
mode="fluent"
111-
value={translations}
112-
annotations={editor_annotations}
113-
onChange={val => this.handleTranslationsChange(val)}
114-
/>
108+
<div className="example-editor">
109+
<Editor
110+
height="10rem"
111+
value={translations}
112+
annotations={editor_annotations}
113+
onChange={val => this.handleTranslationsChange(val)}
114+
/>
115+
</div>
115116

116117
<dl className="variables">
117118
{externals_controls}

0 commit comments

Comments
 (0)