##// END OF EJS Templates
code-mirror: implement slash actions instead of ctrl+space....
marcink -
r1361:9c1873b2 default
parent child Browse files
Show More
@@ -249,6 +249,7 b' var initCommentBoxCodeMirror = function('
249 */
249 */
250
250
251 var filterActions = function(actions, context){
251 var filterActions = function(actions, context){
252
252 var MAX_LIMIT = 10;
253 var MAX_LIMIT = 10;
253 var filtered_actions= [];
254 var filtered_actions = [];
254 var curWord = context.string;
255 var curWord = context.string;
@@ -256,7 +257,7 b' var initCommentBoxCodeMirror = function('
256 cmLog.debug('Filtering actions based on query:', curWord);
257 cmLog.debug('Filtering actions based on query:', curWord);
257 $.each(actions, function(i) {
258 $.each(actions, function(i) {
258 var match = actions[i];
259 var match = actions[i];
259 var searchText = match.displayText;
260 var searchText = match.searchText;
260
261
261 if (!curWord ||
262 if (!curWord ||
262 searchText.toLowerCase().lastIndexOf(curWord) !== -1) {
263 searchText.toLowerCase().lastIndexOf(curWord) !== -1) {
@@ -276,6 +277,7 b' var initCommentBoxCodeMirror = function('
276 return false;
277 return false;
277 }
278 }
278 });
279 });
280
279 return filtered_actions;
281 return filtered_actions;
280 };
282 };
281
283
@@ -284,7 +286,9 b' var initCommentBoxCodeMirror = function('
284 return CodeMirror.Pass;
286 return CodeMirror.Pass;
285 };
287 };
286
288
287 var completeActions = function(cm, pred) {
289 var completeActions = function(actions){
290
291 return function(cm, pred) {
288 var cur = cm.getCursor();
292 var cur = cm.getCursor();
289 var options = {
293 var options = {
290 closeOnUnfocus: true
294 closeOnUnfocus: true
@@ -295,6 +299,11 b' var initCommentBoxCodeMirror = function('
295 CodeMirror.showHint(cm, CodeMirror.hint.actions, options);
299 CodeMirror.showHint(cm, CodeMirror.hint.actions, options);
296 }
300 }
297 }, 100);
301 }, 100);
302
303 // tell CodeMirror we didn't handle the key
304 // trick to trigger on a char but still complete it
305 return CodeMirror.Pass;
306 }
298 };
307 };
299
308
300 var extraKeys = {
309 var extraKeys = {
@@ -314,7 +323,8 b' var initCommentBoxCodeMirror = function('
314 }
323 }
315
324
316 if (triggerActions) {
325 if (triggerActions) {
317 extraKeys["Ctrl-Space"] = completeActions;
326 // register triggerActions for this instance
327 extraKeys["'/'"] = completeActions(triggerActions);
318 }
328 }
319
329
320 var cm = CodeMirror.fromTextArea($(textAreaId).get(0), {
330 var cm = CodeMirror.fromTextArea($(textAreaId).get(0), {
@@ -349,15 +359,16 b' var initCommentBoxCodeMirror = function('
349 var cur = editor.getCursor();
359 var cur = editor.getCursor();
350 var curLine = editor.getLine(cur.line).slice(0, cur.ch);
360 var curLine = editor.getLine(cur.line).slice(0, cur.ch);
351
361
352 var tokenMatch = new RegExp('[a-zA-Z]{1}[a-zA-Z]*$').exec(curLine);
362 // match only on /+1 character minimum
363 var tokenMatch = new RegExp('(^/\|/\)([a-zA-Z]*)$').exec(curLine);
353
364
354 var tokenStr = '';
365 var tokenStr = '';
355 if (tokenMatch !== null && tokenMatch.length > 0){
366 if (tokenMatch !== null && tokenMatch.length > 0){
356 tokenStr = tokenMatch[0].strip();
367 tokenStr = tokenMatch[2].strip();
357 }
368 }
358
369
359 var context = {
370 var context = {
360 start: cur.ch - tokenStr.length,
371 start: (cur.ch - tokenStr.length) - 1,
361 end: cur.ch,
372 end: cur.ch,
362 string: tokenStr,
373 string: tokenStr,
363 type: null
374 type: null
@@ -366,6 +377,7 b' var initCommentBoxCodeMirror = function('
366 var actions = [
377 var actions = [
367 {
378 {
368 text: "approve",
379 text: "approve",
380 searchText: "status approved",
369 displayText: _gettext('Set status to Approved'),
381 displayText: _gettext('Set status to Approved'),
370 hint: function(CodeMirror, data, completion) {
382 hint: function(CodeMirror, data, completion) {
371 CodeMirror.replaceRange("", completion.from || data.from,
383 CodeMirror.replaceRange("", completion.from || data.from,
@@ -384,6 +396,7 b' var initCommentBoxCodeMirror = function('
384 },
396 },
385 {
397 {
386 text: "reject",
398 text: "reject",
399 searchText: "status rejected",
387 displayText: _gettext('Set status to Rejected'),
400 displayText: _gettext('Set status to Rejected'),
388 hint: function(CodeMirror, data, completion) {
401 hint: function(CodeMirror, data, completion) {
389 CodeMirror.replaceRange("", completion.from || data.from,
402 CodeMirror.replaceRange("", completion.from || data.from,
@@ -399,6 +412,44 b' var initCommentBoxCodeMirror = function('
399 el.innerHTML = completion.displayText;
412 el.innerHTML = completion.displayText;
400 elt.appendChild(el);
413 elt.appendChild(el);
401 }
414 }
415 },
416 {
417 text: "as_todo",
418 searchText: "todo comment",
419 displayText: _gettext('TODO comment'),
420 hint: function(CodeMirror, data, completion) {
421 CodeMirror.replaceRange("", completion.from || data.from,
422 completion.to || data.to, "complete");
423 $('#comment_type_general').val('todo')
424 },
425 render: function(elt, data, completion) {
426 var el = document.createElement('div');
427 el.className = "pull-left";
428 elt.appendChild(el);
429
430 el = document.createElement('span');
431 el.innerHTML = completion.displayText;
432 elt.appendChild(el);
433 }
434 },
435 {
436 text: "as_note",
437 searchText: "note comment",
438 displayText: _gettext('Note Comment'),
439 hint: function(CodeMirror, data, completion) {
440 CodeMirror.replaceRange("", completion.from || data.from,
441 completion.to || data.to, "complete");
442 $('#comment_type_general').val('note')
443 },
444 render: function(elt, data, completion) {
445 var el = document.createElement('div');
446 el.className = "pull-left";
447 elt.appendChild(el);
448
449 el = document.createElement('span');
450 el.innerHTML = completion.displayText;
451 elt.appendChild(el);
452 }
402 }
453 }
403 ];
454 ];
404
455
@@ -407,6 +458,7 b' var initCommentBoxCodeMirror = function('
407 from: CodeMirror.Pos(cur.line, context.start),
458 from: CodeMirror.Pos(cur.line, context.start),
408 to: CodeMirror.Pos(cur.line, context.end)
459 to: CodeMirror.Pos(cur.line, context.end)
409 };
460 };
461
410 };
462 };
411 CodeMirror.registerHelper("hint", "mentions", CodeMirrorMentionHint);
463 CodeMirror.registerHelper("hint", "mentions", CodeMirrorMentionHint);
412 CodeMirror.registerHelper("hint", "actions", actionHint);
464 CodeMirror.registerHelper("hint", "actions", actionHint);
General Comments 0
You need to be logged in to leave comments. Login now