1
1
"use strict" ;
2
2
3
3
import { Tooltip } from "bootstrap" ;
4
+ import { Editor } from "./editor.js" ;
4
5
import { StructureView } from "./structure_view.js" ;
5
6
import { SyntaxView } from "./syntax_view.js" ;
6
7
import { StatisticsView } from "./statistics_view.js" ;
7
8
import { WebSocketClient } from "./websocket.js" ;
8
9
import { debounce } from "./debounce.js" ;
9
10
10
- import "../css/editor.css" ;
11
-
12
- import "ace-builds/src-min-noconflict/ace" ;
13
- import "ace-builds/src-min-noconflict/ext-language_tools" ;
14
- import "ace-builds/src-min-noconflict/mode-swift" ;
15
- import "ace-builds/src-min-noconflict/theme-xcode" ;
16
- const Range = ace . require ( "ace/range" ) . Range ;
17
-
18
11
export class App {
19
12
get contentViewHeight ( ) {
20
13
const headerHeight = document . querySelector ( "header" ) . clientHeight ;
@@ -24,30 +17,7 @@ export class App {
24
17
}
25
18
26
19
constructor ( ) {
27
- this . editor = ace . edit ( "editor-container" ) ;
28
- this . editor . setTheme ( "ace/theme/xcode" ) ;
29
- this . editor . session . setMode ( "ace/mode/swift" ) ;
30
- this . editor . $blockScrolling = Infinity ;
31
- this . editor . setOptions ( {
32
- tabSize : 2 ,
33
- useSoftTabs : true ,
34
- autoScrollEditorIntoView : true ,
35
- fontFamily :
36
- "Menlo, Consolas, 'DejaVu Sans Mono', 'Ubuntu Mono', monospace" ,
37
- fontSize : "11pt" ,
38
- showInvisibles : false ,
39
- enableAutoIndent : true ,
40
- enableBasicAutocompletion : true ,
41
- enableSnippets : true ,
42
- enableLiveAutocompletion : true ,
43
- scrollPastEnd : 0.5 , // Overscroll
44
- wrap : "free" ,
45
- displayIndentGuides : true ,
46
- } ) ;
47
- this . editor . renderer . setOptions ( {
48
- showFoldWidgets : false ,
49
- showPrintMargin : false ,
50
- } ) ;
20
+ this . editor = new Editor ( document . getElementById ( "editor-container" ) ) ;
51
21
52
22
this . structureView = new StructureView (
53
23
document . getElementById ( "structure" )
@@ -72,7 +42,7 @@ export class App {
72
42
const updateOnTextChange = debounce ( ( ) => {
73
43
this . update ( ) ;
74
44
} , 400 ) ;
75
- this . editor . on ( "change" , ( change ) => {
45
+ this . editor . on ( "change" , ( ) => {
76
46
updateOnTextChange ( ) ;
77
47
} ) ;
78
48
@@ -107,33 +77,6 @@ export class App {
107
77
formatter . send ( { code : this . editor . getValue ( ) } ) ;
108
78
} ) ;
109
79
110
- const dropZone = document . getElementById ( "editor-container" ) ;
111
- dropZone . addEventListener (
112
- "dragover" ,
113
- ( event ) => {
114
- event . stopPropagation ( ) ;
115
- event . preventDefault ( ) ;
116
- event . dataTransfer . dropEffect = "copy" ;
117
- } ,
118
- false
119
- ) ;
120
- dropZone . addEventListener (
121
- "drop" ,
122
- ( event ) => {
123
- event . stopPropagation ( ) ;
124
- event . preventDefault ( ) ;
125
-
126
- const files = event . dataTransfer . files ;
127
- const reader = new FileReader ( ) ;
128
- reader . onload = ( event ) => {
129
- this . editor . setValue ( event . target . result ) ;
130
- this . editor . clearSelection ( ) ;
131
- } ;
132
- reader . readAsText ( files [ 0 ] , "UTF-8" ) ;
133
- } ,
134
- false
135
- ) ;
136
-
137
80
const onresize = debounce ( ( ) => {
138
81
this . onresize ( ) ;
139
82
} , 200 ) ;
@@ -203,14 +146,7 @@ export class App {
203
146
updateStructure ( structureData ) {
204
147
this . structureView . update ( structureData ) ;
205
148
this . structureView . onmouseover = ( event , target , data ) => {
206
- this . editor . selection . setRange (
207
- new Range (
208
- data . range . startRow - 1 ,
209
- data . range . startColumn - 1 ,
210
- data . range . endRow - 1 ,
211
- data . range . endColumn - 1
212
- )
213
- ) ;
149
+ this . editor . setSelection ( data . range ) ;
214
150
} ;
215
151
}
216
152
@@ -223,27 +159,18 @@ export class App {
223
159
224
160
this . statisticsView . onmouseover = ( event , target , ranges ) => {
225
161
for ( const range of ranges ) {
226
- this . editor . session . addMarker (
227
- new Range (
228
- range . startRow - 1 ,
229
- range . startColumn - 1 ,
230
- range . endRow - 1 ,
231
- range . endColumn - 1
232
- ) ,
233
- "editor-marker" ,
234
- "text"
235
- ) ;
162
+ this . editor . markText ( range ) ;
236
163
}
237
164
} ;
238
165
this . statisticsView . onmouseout = ( event , target ) => {
239
- const markers = this . editor . session . getMarkers ( ) ;
240
- for ( const [ key , value ] of Object . entries ( markers ) ) {
241
- this . editor . session . removeMarker ( value . id ) ;
242
- }
166
+ this . editor . clearMarks ( ) ;
243
167
} ;
244
168
}
245
169
246
170
onresize ( ) {
171
+ document . querySelector ( ".CodeMirror" ) . style . height = this . contentViewHeight ;
172
+ this . editor . refresh ( ) ;
173
+
247
174
document . getElementById ( "structure" ) . style . height = this . contentViewHeight ;
248
175
document . getElementById ( "syntax-container" ) . style . height =
249
176
this . contentViewHeight ;
0 commit comments