ace-rails-ap 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -1
  3. data/lib/ace/rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/ace/ace.js +6911 -5290
  5. data/vendor/assets/javascripts/ace/ext-chromevox.js +537 -0
  6. data/vendor/assets/javascripts/ace/ext-elastic_tabstops_lite.js +301 -0
  7. data/vendor/assets/javascripts/ace/ext-emmet.js +1109 -0
  8. data/vendor/assets/javascripts/ace/ext-keybinding_menu.js +207 -0
  9. data/vendor/assets/javascripts/ace/ext-language_tools.js +1665 -0
  10. data/vendor/assets/javascripts/ace/ext-modelist.js +168 -0
  11. data/vendor/assets/javascripts/ace/ext-old_ie.js +500 -0
  12. data/vendor/assets/javascripts/ace/ext-options.js +252 -0
  13. data/vendor/assets/javascripts/ace/ext-searchbox.js +421 -0
  14. data/vendor/assets/javascripts/ace/ext-settings_menu.js +632 -0
  15. data/vendor/assets/javascripts/ace/ext-spellcheck.js +68 -0
  16. data/vendor/assets/javascripts/ace/ext-split.js +271 -0
  17. data/vendor/assets/javascripts/ace/ext-static_highlight.js +178 -0
  18. data/vendor/assets/javascripts/ace/ext-statusbar.js +47 -0
  19. data/vendor/assets/javascripts/ace/ext-textarea.js +478 -0
  20. data/vendor/assets/javascripts/ace/ext-themelist.js +86 -0
  21. data/vendor/assets/javascripts/ace/ext-whitespace.js +206 -0
  22. data/vendor/assets/javascripts/ace/keybinding-emacs.js +822 -131
  23. data/vendor/assets/javascripts/ace/keybinding-vim.js +382 -258
  24. data/vendor/assets/javascripts/ace/mode-abap.js +261 -0
  25. data/vendor/assets/javascripts/ace/mode-actionscript.js +257 -0
  26. data/vendor/assets/javascripts/ace/mode-ada.js +118 -0
  27. data/vendor/assets/javascripts/ace/mode-asciidoc.js +373 -0
  28. data/vendor/assets/javascripts/ace/mode-assembly_x86.js +217 -0
  29. data/vendor/assets/javascripts/ace/mode-autohotkey.js +225 -0
  30. data/vendor/assets/javascripts/ace/mode-batchfile.js +213 -0
  31. data/vendor/assets/javascripts/ace/mode-c9search.js +144 -124
  32. data/vendor/assets/javascripts/ace/mode-c_cpp.js +296 -254
  33. data/vendor/assets/javascripts/ace/mode-clojure.js +113 -177
  34. data/vendor/assets/javascripts/ace/mode-cobol.js +125 -0
  35. data/vendor/assets/javascripts/ace/mode-coffee.js +152 -235
  36. data/vendor/assets/javascripts/ace/mode-coldfusion.js +823 -835
  37. data/vendor/assets/javascripts/ace/mode-csharp.js +325 -187
  38. data/vendor/assets/javascripts/ace/mode-css.js +583 -297
  39. data/vendor/assets/javascripts/ace/mode-curly.js +2423 -0
  40. data/vendor/assets/javascripts/ace/mode-d.js +492 -0
  41. data/vendor/assets/javascripts/ace/mode-dart.js +993 -0
  42. data/vendor/assets/javascripts/ace/mode-diff.js +124 -204
  43. data/vendor/assets/javascripts/ace/mode-django.js +2448 -0
  44. data/vendor/assets/javascripts/ace/mode-dot.js +361 -0
  45. data/vendor/assets/javascripts/ace/mode-ejs.js +2817 -0
  46. data/vendor/assets/javascripts/ace/mode-erlang.js +987 -0
  47. data/vendor/assets/javascripts/ace/mode-forth.js +280 -0
  48. data/vendor/assets/javascripts/ace/mode-ftl.js +1061 -0
  49. data/vendor/assets/javascripts/ace/mode-glsl.js +313 -275
  50. data/vendor/assets/javascripts/ace/mode-golang.js +268 -275
  51. data/vendor/assets/javascripts/ace/mode-groovy.js +347 -492
  52. data/vendor/assets/javascripts/ace/mode-haml.js +498 -0
  53. data/vendor/assets/javascripts/ace/mode-handlebars.js +2433 -0
  54. data/vendor/assets/javascripts/ace/mode-haskell.js +362 -0
  55. data/vendor/assets/javascripts/ace/mode-haxe.js +226 -202
  56. data/vendor/assets/javascripts/ace/mode-html.js +1099 -802
  57. data/vendor/assets/javascripts/ace/mode-html_completions.js +309 -0
  58. data/vendor/assets/javascripts/ace/mode-html_ruby.js +2822 -0
  59. data/vendor/assets/javascripts/ace/mode-ini.js +185 -0
  60. data/vendor/assets/javascripts/ace/mode-jack.js +653 -0
  61. data/vendor/assets/javascripts/ace/mode-jade.js +2081 -0
  62. data/vendor/assets/javascripts/ace/mode-java.js +339 -488
  63. data/vendor/assets/javascripts/ace/mode-javascript.js +342 -478
  64. data/vendor/assets/javascripts/ace/mode-json.js +215 -178
  65. data/vendor/assets/javascripts/ace/mode-jsoniq.js +2761 -0
  66. data/vendor/assets/javascripts/ace/mode-jsp.js +1553 -0
  67. data/vendor/assets/javascripts/ace/mode-jsx.js +325 -289
  68. data/vendor/assets/javascripts/ace/mode-julia.js +286 -0
  69. data/vendor/assets/javascripts/ace/mode-latex.js +141 -46
  70. data/vendor/assets/javascripts/ace/mode-less.js +493 -151
  71. data/vendor/assets/javascripts/ace/mode-liquid.js +594 -656
  72. data/vendor/assets/javascripts/ace/mode-lisp.js +137 -0
  73. data/vendor/assets/javascripts/ace/mode-livescript.js +288 -0
  74. data/vendor/assets/javascripts/ace/mode-logiql.js +669 -0
  75. data/vendor/assets/javascripts/ace/mode-lsl.js +890 -0
  76. data/vendor/assets/javascripts/ace/mode-lua.js +274 -368
  77. data/vendor/assets/javascripts/ace/mode-luapage.js +1331 -1107
  78. data/vendor/assets/javascripts/ace/mode-lucene.js +64 -0
  79. data/vendor/assets/javascripts/ace/mode-makefile.js +332 -0
  80. data/vendor/assets/javascripts/ace/mode-markdown.js +1303 -948
  81. data/vendor/assets/javascripts/ace/mode-matlab.js +230 -0
  82. data/vendor/assets/javascripts/ace/mode-mushcode.js +705 -0
  83. data/vendor/assets/javascripts/ace/mode-mushcode_high_rules.js +569 -0
  84. data/vendor/assets/javascripts/ace/mode-mysql.js +185 -0
  85. data/vendor/assets/javascripts/ace/mode-nix.js +935 -0
  86. data/vendor/assets/javascripts/ace/mode-objectivec.js +699 -0
  87. data/vendor/assets/javascripts/ace/mode-ocaml.js +44 -63
  88. data/vendor/assets/javascripts/ace/mode-pascal.js +233 -0
  89. data/vendor/assets/javascripts/ace/mode-perl.js +116 -189
  90. data/vendor/assets/javascripts/ace/mode-pgsql.js +886 -500
  91. data/vendor/assets/javascripts/ace/mode-php.js +1158 -380
  92. data/vendor/assets/javascripts/ace/mode-plain_text.js +56 -0
  93. data/vendor/assets/javascripts/ace/mode-powershell.js +222 -167
  94. data/vendor/assets/javascripts/ace/mode-prolog.js +354 -0
  95. data/vendor/assets/javascripts/ace/mode-properties.js +100 -0
  96. data/vendor/assets/javascripts/ace/mode-protobuf.js +885 -0
  97. data/vendor/assets/javascripts/ace/mode-python.js +99 -201
  98. data/vendor/assets/javascripts/ace/mode-r.js +337 -0
  99. data/vendor/assets/javascripts/ace/mode-rdoc.js +210 -0
  100. data/vendor/assets/javascripts/ace/mode-rhtml.js +2663 -0
  101. data/vendor/assets/javascripts/ace/mode-ruby.js +262 -136
  102. data/vendor/assets/javascripts/ace/mode-rust.js +245 -0
  103. data/vendor/assets/javascripts/ace/mode-sass.js +443 -0
  104. data/vendor/assets/javascripts/ace/mode-scad.js +225 -240
  105. data/vendor/assets/javascripts/ace/mode-scala.js +340 -494
  106. data/vendor/assets/javascripts/ace/mode-scheme.js +143 -0
  107. data/vendor/assets/javascripts/ace/mode-scss.js +499 -157
  108. data/vendor/assets/javascripts/ace/mode-sh.js +180 -110
  109. data/vendor/assets/javascripts/ace/mode-sjs.js +1154 -0
  110. data/vendor/assets/javascripts/ace/mode-snippets.js +198 -0
  111. data/vendor/assets/javascripts/ace/mode-soy_template.js +2707 -0
  112. data/vendor/assets/javascripts/ace/mode-space.js +160 -0
  113. data/vendor/assets/javascripts/ace/mode-sql.js +48 -69
  114. data/vendor/assets/javascripts/ace/mode-stylus.js +447 -0
  115. data/vendor/assets/javascripts/ace/mode-svg.js +552 -605
  116. data/vendor/assets/javascripts/ace/mode-tcl.js +139 -98
  117. data/vendor/assets/javascripts/ace/mode-tex.js +187 -0
  118. data/vendor/assets/javascripts/ace/mode-textile.js +29 -40
  119. data/vendor/assets/javascripts/ace/mode-tmsnippet.js +200 -0
  120. data/vendor/assets/javascripts/ace/mode-toml.js +177 -0
  121. data/vendor/assets/javascripts/ace/mode-twig.js +2228 -0
  122. data/vendor/assets/javascripts/ace/mode-typescript.js +1018 -0
  123. data/vendor/assets/javascripts/ace/mode-vbscript.js +250 -0
  124. data/vendor/assets/javascripts/ace/mode-velocity.js +1621 -0
  125. data/vendor/assets/javascripts/ace/mode-verilog.js +127 -0
  126. data/vendor/assets/javascripts/ace/mode-vhdl.js +139 -0
  127. data/vendor/assets/javascripts/ace/mode-xml.js +350 -242
  128. data/vendor/assets/javascripts/ace/mode-xquery.js +2490 -300
  129. data/vendor/assets/javascripts/ace/mode-yaml.js +146 -45
  130. data/vendor/assets/javascripts/ace/theme-ambiance.js +202 -0
  131. data/vendor/assets/javascripts/ace/theme-chaos.js +179 -0
  132. data/vendor/assets/javascripts/ace/theme-chrome.js +97 -153
  133. data/vendor/assets/javascripts/ace/theme-clouds.js +78 -119
  134. data/vendor/assets/javascripts/ace/theme-clouds_midnight.js +79 -120
  135. data/vendor/assets/javascripts/ace/theme-cobalt.js +89 -140
  136. data/vendor/assets/javascripts/ace/theme-crimson_editor.js +93 -145
  137. data/vendor/assets/javascripts/ace/theme-dawn.js +84 -143
  138. data/vendor/assets/javascripts/ace/theme-dreamweaver.js +99 -162
  139. data/vendor/assets/javascripts/ace/theme-eclipse.js +78 -111
  140. data/vendor/assets/javascripts/ace/theme-github.js +70 -121
  141. data/vendor/assets/javascripts/ace/theme-idle_fingers.js +75 -134
  142. data/vendor/assets/javascripts/ace/theme-kr.js +135 -0
  143. data/vendor/assets/javascripts/ace/theme-merbivore.js +80 -143
  144. data/vendor/assets/javascripts/ace/theme-merbivore_soft.js +81 -149
  145. data/vendor/assets/javascripts/ace/theme-mono_industrial.js +87 -146
  146. data/vendor/assets/javascripts/ace/theme-monokai.js +88 -146
  147. data/vendor/assets/javascripts/ace/theme-pastel_on_dark.js +82 -142
  148. data/vendor/assets/javascripts/ace/theme-solarized_dark.js +83 -144
  149. data/vendor/assets/javascripts/ace/theme-solarized_light.js +76 -133
  150. data/vendor/assets/javascripts/ace/theme-terminal.js +145 -0
  151. data/vendor/assets/javascripts/ace/theme-textmate.js +101 -158
  152. data/vendor/assets/javascripts/ace/theme-tomorrow.js +89 -163
  153. data/vendor/assets/javascripts/ace/theme-tomorrow_night.js +89 -163
  154. data/vendor/assets/javascripts/ace/theme-tomorrow_night_blue.js +89 -165
  155. data/vendor/assets/javascripts/ace/theme-tomorrow_night_bright.js +101 -162
  156. data/vendor/assets/javascripts/ace/theme-tomorrow_night_eighties.js +90 -160
  157. data/vendor/assets/javascripts/ace/theme-twilight.js +87 -158
  158. data/vendor/assets/javascripts/ace/theme-vibrant_ink.js +75 -140
  159. data/vendor/assets/javascripts/ace/theme-xcode.js +120 -0
  160. data/vendor/assets/javascripts/ace/worker-coffee.js +3049 -2665
  161. data/vendor/assets/javascripts/ace/worker-css.js +1779 -4376
  162. data/vendor/assets/javascripts/ace/worker-javascript.js +8701 -9008
  163. data/vendor/assets/javascripts/ace/worker-json.js +709 -1340
  164. data/vendor/assets/javascripts/ace/worker-lua.js +3525 -0
  165. data/vendor/assets/javascripts/ace/worker-php.js +6893 -0
  166. data/vendor/assets/javascripts/ace/worker-xquery.js +19924 -64507
  167. metadata +100 -17
@@ -0,0 +1,537 @@
1
+ define('ace/ext/chromevox', ['require', 'exports', 'module' , 'ace/editor', 'ace/config'], function(require, exports, module) {
2
+ var cvoxAce = {};
3
+ cvoxAce.SpeechProperty;
4
+ cvoxAce.Cursor;
5
+ cvoxAce.Token;
6
+ cvoxAce.Annotation;
7
+ var CONSTANT_PROP = {
8
+ 'rate': 0.8,
9
+ 'pitch': 0.4,
10
+ 'volume': 0.9
11
+ };
12
+ var DEFAULT_PROP = {
13
+ 'rate': 1,
14
+ 'pitch': 0.5,
15
+ 'volume': 0.9
16
+ };
17
+ var ENTITY_PROP = {
18
+ 'rate': 0.8,
19
+ 'pitch': 0.8,
20
+ 'volume': 0.9
21
+ };
22
+ var KEYWORD_PROP = {
23
+ 'rate': 0.8,
24
+ 'pitch': 0.3,
25
+ 'volume': 0.9
26
+ };
27
+ var STORAGE_PROP = {
28
+ 'rate': 0.8,
29
+ 'pitch': 0.7,
30
+ 'volume': 0.9
31
+ };
32
+ var VARIABLE_PROP = {
33
+ 'rate': 0.8,
34
+ 'pitch': 0.8,
35
+ 'volume': 0.9
36
+ };
37
+ var DELETED_PROP = {
38
+ 'punctuationEcho': 'none',
39
+ 'relativePitch': -0.6
40
+ };
41
+ var ERROR_EARCON = 'ALERT_NONMODAL';
42
+ var MODE_SWITCH_EARCON = 'ALERT_MODAL';
43
+ var NO_MATCH_EARCON = 'INVALID_KEYPRESS';
44
+ var INSERT_MODE_STATE = 'insertMode';
45
+ var COMMAND_MODE_STATE = 'start';
46
+
47
+ var REPLACE_LIST = [
48
+ {
49
+ substr: ';',
50
+ newSubstr: ' semicolon '
51
+ },
52
+ {
53
+ substr: ':',
54
+ newSubstr: ' colon '
55
+ }
56
+ ];
57
+ var Command = {
58
+ SPEAK_ANNOT: 'annots',
59
+ SPEAK_ALL_ANNOTS: 'all_annots',
60
+ TOGGLE_LOCATION: 'toggle_location',
61
+ SPEAK_MODE: 'mode',
62
+ SPEAK_ROW_COL: 'row_col',
63
+ TOGGLE_DISPLACEMENT: 'toggle_displacement',
64
+ FOCUS_TEXT: 'focus_text'
65
+ };
66
+ var KEY_PREFIX = 'CONTROL + SHIFT ';
67
+ cvoxAce.editor = null;
68
+ var lastCursor = null;
69
+ var annotTable = {};
70
+ var shouldSpeakRowLocation = false;
71
+ var shouldSpeakDisplacement = false;
72
+ var changed = false;
73
+ var vimState = null;
74
+ var keyCodeToShortcutMap = {};
75
+ var cmdToShortcutMap = {};
76
+ var getKeyShortcutString = function(keyCode) {
77
+ return KEY_PREFIX + String.fromCharCode(keyCode);
78
+ };
79
+ var isVimMode = function() {
80
+ var keyboardHandler = cvoxAce.editor.keyBinding.getKeyboardHandler();
81
+ return keyboardHandler.$id === 'ace/keyboard/vim';
82
+ };
83
+ var getCurrentToken = function(cursor) {
84
+ return cvoxAce.editor.getSession().getTokenAt(cursor.row, cursor.column + 1);
85
+ };
86
+ var getCurrentLine = function(cursor) {
87
+ return cvoxAce.editor.getSession().getLine(cursor.row);
88
+ };
89
+ var onRowChange = function(currCursor) {
90
+ if (annotTable[currCursor.row]) {
91
+ cvox.Api.playEarcon(ERROR_EARCON);
92
+ }
93
+ if (shouldSpeakRowLocation) {
94
+ cvox.Api.stop();
95
+ speakChar(currCursor);
96
+ speakTokenQueue(getCurrentToken(currCursor));
97
+ speakLine(currCursor.row, 1);
98
+ } else {
99
+ speakLine(currCursor.row, 0);
100
+ }
101
+ };
102
+ var isWord = function(cursor) {
103
+ var line = getCurrentLine(cursor);
104
+ var lineSuffix = line.substr(cursor.column - 1);
105
+ if (cursor.column === 0) {
106
+ lineSuffix = ' ' + line;
107
+ }
108
+ var firstWordRegExp = /^\W(\w+)/;
109
+ var words = firstWordRegExp.exec(lineSuffix);
110
+ return words !== null;
111
+ };
112
+ var rules = {
113
+ 'constant': {
114
+ prop: CONSTANT_PROP
115
+ },
116
+ 'entity': {
117
+ prop: ENTITY_PROP
118
+ },
119
+ 'keyword': {
120
+ prop: KEYWORD_PROP
121
+ },
122
+ 'storage': {
123
+ prop: STORAGE_PROP
124
+ },
125
+ 'variable': {
126
+ prop: VARIABLE_PROP
127
+ },
128
+ 'meta': {
129
+ prop: DEFAULT_PROP,
130
+ replace: [
131
+ {
132
+ substr: '</',
133
+ newSubstr: ' closing tag '
134
+ },
135
+ {
136
+ substr: '/>',
137
+ newSubstr: ' close tag '
138
+ },
139
+ {
140
+ substr: '<',
141
+ newSubstr: ' tag start '
142
+ },
143
+ {
144
+ substr: '>',
145
+ newSubstr: ' tag end '
146
+ }
147
+ ]
148
+ }
149
+ };
150
+ var DEFAULT_RULE = {
151
+ prop: DEFAULT_RULE
152
+ };
153
+ var expand = function(value, replaceRules) {
154
+ var newValue = value;
155
+ for (var i = 0; i < replaceRules.length; i++) {
156
+ var replaceRule = replaceRules[i];
157
+ var regexp = new RegExp(replaceRule.substr, 'g');
158
+ newValue = newValue.replace(regexp, replaceRule.newSubstr);
159
+ }
160
+ return newValue;
161
+ };
162
+ var mergeTokens = function(tokens, start, end) {
163
+ var newToken = {};
164
+ newToken.value = '';
165
+ newToken.type = tokens[start].type;
166
+ for (var j = start; j < end; j++) {
167
+ newToken.value += tokens[j].value;
168
+ }
169
+ return newToken;
170
+ };
171
+ var mergeLikeTokens = function(tokens) {
172
+ if (tokens.length <= 1) {
173
+ return tokens;
174
+ }
175
+ var newTokens = [];
176
+ var lastLikeIndex = 0;
177
+ for (var i = 1; i < tokens.length; i++) {
178
+ var lastLikeToken = tokens[lastLikeIndex];
179
+ var currToken = tokens[i];
180
+ if (getTokenRule(lastLikeToken) !== getTokenRule(currToken)) {
181
+ newTokens.push(mergeTokens(tokens, lastLikeIndex, i));
182
+ lastLikeIndex = i;
183
+ }
184
+ }
185
+ newTokens.push(mergeTokens(tokens, lastLikeIndex, tokens.length));
186
+ return newTokens;
187
+ };
188
+ var isRowWhiteSpace = function(row) {
189
+ var line = cvoxAce.editor.getSession().getLine(row);
190
+ var whiteSpaceRegexp = /^\s*$/;
191
+ return whiteSpaceRegexp.exec(line) !== null;
192
+ };
193
+ var speakLine = function(row, queue) {
194
+ var tokens = cvoxAce.editor.getSession().getTokens(row);
195
+ if (tokens.length === 0 || isRowWhiteSpace(row)) {
196
+ cvox.Api.playEarcon('EDITABLE_TEXT');
197
+ return;
198
+ }
199
+ tokens = mergeLikeTokens(tokens);
200
+ var firstToken = tokens[0];
201
+ tokens = tokens.filter(function(token) {
202
+ return token !== firstToken;
203
+ });
204
+ speakToken_(firstToken, queue);
205
+ tokens.forEach(speakTokenQueue);
206
+ };
207
+ var speakTokenFlush = function(token) {
208
+ speakToken_(token, 0);
209
+ };
210
+ var speakTokenQueue = function(token) {
211
+ speakToken_(token, 1);
212
+ };
213
+ var getTokenRule = function(token) {
214
+ if (!token || !token.type) {
215
+ return;
216
+ }
217
+ var split = token.type.split('.');
218
+ if (split.length === 0) {
219
+ return;
220
+ }
221
+ var type = split[0];
222
+ var rule = rules[type];
223
+ if (!rule) {
224
+ return DEFAULT_RULE;
225
+ }
226
+ return rule;
227
+ };
228
+ var speakToken_ = function(token, queue) {
229
+ var rule = getTokenRule(token);
230
+ var value = expand(token.value, REPLACE_LIST);
231
+ if (rule.replace) {
232
+ value = expand(value, rule.replace);
233
+ }
234
+ cvox.Api.speak(value, queue, rule.prop);
235
+ };
236
+ var speakChar = function(cursor) {
237
+ var line = getCurrentLine(cursor);
238
+ cvox.Api.speak(line[cursor.column], 1);
239
+ };
240
+ var speakDisplacement = function(lastCursor, currCursor) {
241
+ var line = getCurrentLine(currCursor);
242
+ var displace = line.substring(lastCursor.column, currCursor.column);
243
+ displace = displace.replace(/ /g, ' space ');
244
+ cvox.Api.speak(displace);
245
+ };
246
+ var speakCharOrWordOrLine = function(lastCursor, currCursor) {
247
+ if (Math.abs(lastCursor.column - currCursor.column) !== 1) {
248
+ var currLineLength = getCurrentLine(currCursor).length;
249
+ if (currCursor.column === 0 || currCursor.column === currLineLength) {
250
+ speakLine(currCursor.row, 0);
251
+ return;
252
+ }
253
+ if (isWord(currCursor)) {
254
+ cvox.Api.stop();
255
+ speakTokenQueue(getCurrentToken(currCursor));
256
+ return;
257
+ }
258
+ }
259
+ speakChar(currCursor);
260
+ };
261
+ var onColumnChange = function(lastCursor, currCursor) {
262
+ if (!cvoxAce.editor.selection.isEmpty()) {
263
+ speakDisplacement(lastCursor, currCursor);
264
+ cvox.Api.speak('selected', 1);
265
+ }
266
+ else if (shouldSpeakDisplacement) {
267
+ speakDisplacement(lastCursor, currCursor);
268
+ } else {
269
+ speakCharOrWordOrLine(lastCursor, currCursor);
270
+ }
271
+ };
272
+ var onCursorChange = function(evt) {
273
+ if (changed) {
274
+ changed = false;
275
+ return;
276
+ }
277
+ var currCursor = cvoxAce.editor.selection.getCursor();
278
+ if (currCursor.row !== lastCursor.row) {
279
+ onRowChange(currCursor);
280
+ } else {
281
+ onColumnChange(lastCursor, currCursor);
282
+ }
283
+ lastCursor = currCursor;
284
+ };
285
+ var onSelectionChange = function(evt) {
286
+ if (cvoxAce.editor.selection.isEmpty()) {
287
+ cvox.Api.speak('unselected');
288
+ }
289
+ };
290
+ var onChange = function(evt) {
291
+ var data = evt.data;
292
+ switch (data.action) {
293
+ case 'removeText':
294
+ cvox.Api.speak(data.text, 0, DELETED_PROP);
295
+ changed = true;
296
+ break;
297
+ case 'insertText':
298
+ cvox.Api.speak(data.text, 0);
299
+ changed = true;
300
+ break;
301
+ }
302
+ };
303
+ var isNewAnnotation = function(annot) {
304
+ var row = annot.row;
305
+ var col = annot.column;
306
+ return !annotTable[row] || !annotTable[row][col];
307
+ };
308
+ var populateAnnotations = function(annotations) {
309
+ annotTable = {};
310
+ for (var i = 0; i < annotations.length; i++) {
311
+ var annotation = annotations[i];
312
+ var row = annotation.row;
313
+ var col = annotation.column;
314
+ if (!annotTable[row]) {
315
+ annotTable[row] = {};
316
+ }
317
+ annotTable[row][col] = annotation;
318
+ }
319
+ };
320
+ var onAnnotationChange = function(evt) {
321
+ var annotations = cvoxAce.editor.getSession().getAnnotations();
322
+ var newAnnotations = annotations.filter(isNewAnnotation);
323
+ if (newAnnotations.length > 0) {
324
+ cvox.Api.playEarcon(ERROR_EARCON);
325
+ }
326
+ populateAnnotations(annotations);
327
+ };
328
+ var speakAnnot = function(annot) {
329
+ var annotText = annot.type + ' ' + annot.text + ' on ' +
330
+ rowColToString(annot.row, annot.column);
331
+ annotText = annotText.replace(';', 'semicolon');
332
+ cvox.Api.speak(annotText, 1);
333
+ };
334
+ var speakAnnotsByRow = function(row) {
335
+ var annots = annotTable[row];
336
+ for (var col in annots) {
337
+ speakAnnot(annots[col]);
338
+ }
339
+ };
340
+ var rowColToString = function(row, col) {
341
+ return 'row ' + (row + 1) + ' column ' + (col + 1);
342
+ };
343
+ var speakCurrRowAndCol = function() {
344
+ cvox.Api.speak(rowColToString(lastCursor.row, lastCursor.column));
345
+ };
346
+ var speakAllAnnots = function() {
347
+ for (var row in annotTable) {
348
+ speakAnnotsByRow(row);
349
+ }
350
+ };
351
+ var speakMode = function() {
352
+ if (!isVimMode()) {
353
+ return;
354
+ }
355
+ switch (cvoxAce.editor.keyBinding.$data.state) {
356
+ case INSERT_MODE_STATE:
357
+ cvox.Api.speak('Insert mode');
358
+ break;
359
+ case COMMAND_MODE_STATE:
360
+ cvox.Api.speak('Command mode');
361
+ break;
362
+ }
363
+ };
364
+ var toggleSpeakRowLocation = function() {
365
+ shouldSpeakRowLocation = !shouldSpeakRowLocation;
366
+ if (shouldSpeakRowLocation) {
367
+ cvox.Api.speak('Speak location on row change enabled.');
368
+ } else {
369
+ cvox.Api.speak('Speak location on row change disabled.');
370
+ }
371
+ };
372
+ var toggleSpeakDisplacement = function() {
373
+ shouldSpeakDisplacement = !shouldSpeakDisplacement;
374
+ if (shouldSpeakDisplacement) {
375
+ cvox.Api.speak('Speak displacement on column changes.');
376
+ } else {
377
+ cvox.Api.speak('Speak current character or word on column changes.');
378
+ }
379
+ };
380
+ var onKeyDown = function(evt) {
381
+ if (evt.ctrlKey && evt.shiftKey) {
382
+ var shortcut = keyCodeToShortcutMap[evt.keyCode];
383
+ if (shortcut) {
384
+ shortcut.func();
385
+ }
386
+ }
387
+ };
388
+ var onChangeStatus = function(evt, editor) {
389
+ if (!isVimMode()) {
390
+ return;
391
+ }
392
+ var state = editor.keyBinding.$data.state;
393
+ if (state === vimState) {
394
+ return;
395
+ }
396
+ switch (state) {
397
+ case INSERT_MODE_STATE:
398
+ cvox.Api.playEarcon(MODE_SWITCH_EARCON);
399
+ cvox.Api.setKeyEcho(true);
400
+ break;
401
+ case COMMAND_MODE_STATE:
402
+ cvox.Api.playEarcon(MODE_SWITCH_EARCON);
403
+ cvox.Api.setKeyEcho(false);
404
+ break;
405
+ }
406
+ vimState = state;
407
+ };
408
+ var contextMenuHandler = function(evt) {
409
+ var cmd = evt.detail['customCommand'];
410
+ var shortcut = cmdToShortcutMap[cmd];
411
+ if (shortcut) {
412
+ shortcut.func();
413
+ cvoxAce.editor.focus();
414
+ }
415
+ };
416
+ var initContextMenu = function() {
417
+ var ACTIONS = SHORTCUTS.map(function(shortcut) {
418
+ return {
419
+ desc: shortcut.desc + getKeyShortcutString(shortcut.keyCode),
420
+ cmd: shortcut.cmd
421
+ };
422
+ });
423
+ var body = document.querySelector('body');
424
+ body.setAttribute('contextMenuActions', JSON.stringify(ACTIONS));
425
+ body.addEventListener('ATCustomEvent', contextMenuHandler, true);
426
+ };
427
+ var onFindSearchbox = function(evt) {
428
+ if (evt.match) {
429
+ speakLine(lastCursor.row, 0);
430
+ } else {
431
+ cvox.Api.playEarcon(NO_MATCH_EARCON);
432
+ }
433
+ };
434
+ var focus = function() {
435
+ cvoxAce.editor.focus();
436
+ };
437
+ var SHORTCUTS = [
438
+ {
439
+ keyCode: 49,
440
+ func: function() {
441
+ speakAnnotsByRow(lastCursor.row);
442
+ },
443
+ cmd: Command.SPEAK_ANNOT,
444
+ desc: 'Speak annotations on line'
445
+ },
446
+ {
447
+ keyCode: 50,
448
+ func: speakAllAnnots,
449
+ cmd: Command.SPEAK_ALL_ANNOTS,
450
+ desc: 'Speak all annotations'
451
+ },
452
+ {
453
+ keyCode: 51,
454
+ func: speakMode,
455
+ cmd: Command.SPEAK_MODE,
456
+ desc: 'Speak Vim mode'
457
+ },
458
+ {
459
+ keyCode: 52,
460
+ func: toggleSpeakRowLocation,
461
+ cmd: Command.TOGGLE_LOCATION,
462
+ desc: 'Toggle speak row location'
463
+ },
464
+ {
465
+ keyCode: 53,
466
+ func: speakCurrRowAndCol,
467
+ cmd: Command.SPEAK_ROW_COL,
468
+ desc: 'Speak row and column'
469
+ },
470
+ {
471
+ keyCode: 54,
472
+ func: toggleSpeakDisplacement,
473
+ cmd: Command.TOGGLE_DISPLACEMENT,
474
+ desc: 'Toggle speak displacement'
475
+ },
476
+ {
477
+ keyCode: 55,
478
+ func: focus,
479
+ cmd: Command.FOCUS_TEXT,
480
+ desc: 'Focus text'
481
+ }
482
+ ];
483
+ var onFocus = function() {
484
+ cvoxAce.editor = editor;
485
+ editor.getSession().selection.on('changeCursor', onCursorChange);
486
+ editor.getSession().selection.on('changeSelection', onSelectionChange);
487
+ editor.getSession().on('change', onChange);
488
+ editor.getSession().on('changeAnnotation', onAnnotationChange);
489
+ editor.on('changeStatus', onChangeStatus);
490
+ editor.on('findSearchBox', onFindSearchbox);
491
+ editor.container.addEventListener('keydown', onKeyDown);
492
+
493
+ lastCursor = editor.selection.getCursor();
494
+ };
495
+ var init = function(editor) {
496
+ onFocus();
497
+ SHORTCUTS.forEach(function(shortcut) {
498
+ keyCodeToShortcutMap[shortcut.keyCode] = shortcut;
499
+ cmdToShortcutMap[shortcut.cmd] = shortcut;
500
+ });
501
+
502
+ editor.on('focus', onFocus);
503
+ if (isVimMode()) {
504
+ cvox.Api.setKeyEcho(false);
505
+ }
506
+ initContextMenu();
507
+ };
508
+ function cvoxApiExists() {
509
+ return (typeof(cvox) !== 'undefined') && cvox && cvox.Api;
510
+ }
511
+ var tries = 0;
512
+ var MAX_TRIES = 15;
513
+ function watchForCvoxLoad(editor) {
514
+ if (cvoxApiExists()) {
515
+ init(editor);
516
+ } else {
517
+ tries++;
518
+ if (tries >= MAX_TRIES) {
519
+ return;
520
+ }
521
+ window.setTimeout(watchForCvoxLoad, 500, editor);
522
+ }
523
+ }
524
+
525
+ var Editor = require('../editor').Editor;
526
+ require('../config').defineOptions(Editor.prototype, 'editor', {
527
+ enableChromevoxEnhancements: {
528
+ set: function(val) {
529
+ if (val) {
530
+ watchForCvoxLoad(this);
531
+ }
532
+ },
533
+ value: true // turn it on by default or check for window.cvox
534
+ }
535
+ });
536
+
537
+ });