@@ -9,19 +9,24 @@ require('codemirror/addon/selection/mark-selection');
99require ( 'codemirror/lib/codemirror.css' ) ;
1010require ( '../../assets/theme/parallax.css' ) ;
1111
12+ const React = require ( 'react' ) ;
1213const CodeMirror = require ( 'codemirror' ) ;
1314require ( './pbasic' ) ( CodeMirror ) ;
1415
1516const keyExtension = require ( './key-extension' ) ;
17+
1618const consoleStore = require ( '../../src/stores/console' ) ;
1719const editorStore = require ( '../../src/stores/editor' ) ;
20+ const deviceStore = require ( '../../src/stores/device' ) ;
1821const fileStore = require ( '../../src/stores/file' ) ;
22+
1923const { handleInput } = require ( '../../src/actions/editor' ) ;
2024const DocumentsStore = require ( '../../src/stores/documents' ) ;
2125
22- const React = require ( 'react' ) ;
2326const TransmissionBar = require ( './transmission-bar' ) ;
2427
28+ const makeToasts = require ( '../../src/lib/toasts' ) ;
29+
2530function editor ( app , opts , done ) {
2631
2732 var codeEditor ;
@@ -37,9 +42,39 @@ function editor(app, opts, done){
3742 }
3843 }
3944
45+ function highlighter ( position , length ) {
46+ if ( ! codeEditor ) {
47+ return ;
48+ }
49+
50+ const doc = codeEditor . getDoc ( ) ;
51+
52+ const anchor = doc . posFromIndex ( position ) ;
53+ const head = doc . posFromIndex ( position + length ) ;
54+
55+ doc . setSelection ( anchor , head , { scroll : false } ) ;
56+
57+ const charRect = codeEditor . charCoords ( anchor , 'local' ) ;
58+ const halfHeight = codeEditor . getScrollerElement ( ) . offsetHeight / 2 ;
59+ const halfTextHeight = Math . floor ( ( charRect . bottom - charRect . top ) / 2 ) ;
60+ codeEditor . scrollTo ( null , charRect . top - halfHeight - halfTextHeight ) ;
61+ }
62+
4063 consoleStore . listen ( refreshConsole ) ;
4164
42- var space = app . workspace ;
65+ const space = app . workspace ;
66+ const compile = app . compile . bind ( app ) ;
67+ // seems strange to pass highlighter to toasts
68+ // maybe this should be named "handlers" or something
69+ const toasts = makeToasts ( app . toast , highlighter ) ;
70+
71+ editorStore . toasts = toasts ;
72+ editorStore . compile = compile ;
73+ editorStore . workspace = space ;
74+
75+ // really stinks to attach these in here
76+ fileStore . toasts = toasts ;
77+ deviceStore . toasts = toasts ;
4378
4479 app . view ( 'editor' , function ( el , cb ) {
4580 console . log ( 'editor render' ) ;
@@ -67,7 +102,8 @@ function editor(app, opts, done){
67102 'Ctrl-Up' : false ,
68103 'Ctrl-Down' : false ,
69104 'Tab' : false ,
70- 'Shift-Tab' : false
105+ 'Shift-Tab' : false ,
106+ 'Ctrl-T' : false
71107 } ) ;
72108 keyExtension . setup ( app ) ;
73109 editorStore . cm = codeEditor ;
0 commit comments