File tree 2 files changed +64
-4
lines changed
2 files changed +64
-4
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < script src ="../demo/kitchen-sink/require.js "> </ script >
6
+ < script type ="text/javascript ">
7
+ require . config ( {
8
+ paths : { ace : "../lib/ace" } ,
9
+ waitSeconds : 0
10
+ } ) ;
11
+ </ script >
12
+ </ head >
13
+ < body >
14
+ < p > < button onclick ="toggleEditor() "> Toggle editor</ button > </ p >
15
+
16
+ < div id ="container "> </ div >
17
+ < script >
18
+ var editor ;
19
+ var counter = 0
20
+
21
+ function toggleEditor ( ) {
22
+ if ( ! editor ) {
23
+ var root = document . createElement ( "div" ) ;
24
+ root . style . height = "100px" ;
25
+ root . setAttribute ( "id" , "editor" ) ;
26
+ root . textContent = "function foo(items) {\nvar x = 'All this is syntax highlighted';\nreturn x;\n}" ;
27
+
28
+ document . getElementById ( "container" ) . appendChild ( root ) ;
29
+
30
+ editor = ace . edit ( root ) ;
31
+
32
+ if ( counter ++ % 2 )
33
+ editor . setTheme ( "ace/theme/monokai" ) ;
34
+ else
35
+ editor . setTheme ( "ace/theme/clouds" ) ;
36
+
37
+ editor . session . setMode ( "ace/mode/javascript" ) ;
38
+ } else {
39
+ editor . destroy ( ) ;
40
+ var el = editor . container ;
41
+ el . parentNode . removeChild ( el ) ;
42
+
43
+ editor . container = null
44
+ editor . renderer = null
45
+
46
+ editor = null ;
47
+
48
+ var root = document . getElementById ( "editor" )
49
+ if ( root )
50
+ root . parentNode . removeChild ( root ) ;
51
+ }
52
+ }
53
+ require ( [ "ace/ace" ] , function ( ace ) {
54
+ window . ace = ace ;
55
+ toggleEditor ( ) ;
56
+ } )
57
+ </ script >
58
+ </ body >
59
+ </ html >
Original file line number Diff line number Diff line change @@ -326,13 +326,14 @@ exports.addCommandKeyListener = function(el, callback) {
326
326
} ) ;
327
327
328
328
if ( ! pressedKeys ) {
329
- pressedKeys = Object . create ( null ) ;
330
- addListener ( window , "focus" , function ( e ) {
331
- pressedKeys = Object . create ( null ) ;
332
- } ) ;
329
+ resetPressedKeys ( ) ;
330
+ addListener ( window , "focus" , resetPressedKeys ) ;
333
331
}
334
332
}
335
333
} ;
334
+ function resetPressedKeys ( e ) {
335
+ pressedKeys = Object . create ( null ) ;
336
+ }
336
337
337
338
if ( window . postMessage && ! useragent . isOldIE ) {
338
339
var postMessageId = 1 ;
You can’t perform that action at this time.
0 commit comments