Show More
@@ -249,14 +249,15 b' var initCommentBoxCodeMirror = function(' | |||
|
249 | 249 | */ |
|
250 | 250 | |
|
251 | 251 | var filterActions = function(actions, context){ |
|
252 | ||
|
252 | 253 | var MAX_LIMIT = 10; |
|
253 | var filtered_actions= []; | |
|
254 | var filtered_actions = []; | |
|
254 | 255 | var curWord = context.string; |
|
255 | 256 | |
|
256 | 257 | cmLog.debug('Filtering actions based on query:', curWord); |
|
257 | 258 | $.each(actions, function(i) { |
|
258 | 259 | var match = actions[i]; |
|
259 |
var searchText = match. |
|
|
260 | var searchText = match.searchText; | |
|
260 | 261 | |
|
261 | 262 | if (!curWord || |
|
262 | 263 | searchText.toLowerCase().lastIndexOf(curWord) !== -1) { |
@@ -276,6 +277,7 b' var initCommentBoxCodeMirror = function(' | |||
|
276 | 277 | return false; |
|
277 | 278 | } |
|
278 | 279 | }); |
|
280 | ||
|
279 | 281 | return filtered_actions; |
|
280 | 282 | }; |
|
281 | 283 | |
@@ -284,17 +286,24 b' var initCommentBoxCodeMirror = function(' | |||
|
284 | 286 | return CodeMirror.Pass; |
|
285 | 287 | }; |
|
286 | 288 | |
|
287 |
var completeActions = function( |
|
|
288 | var cur = cm.getCursor(); | |
|
289 | var options = { | |
|
290 | closeOnUnfocus: true | |
|
291 | }; | |
|
292 | setTimeout(function() { | |
|
293 | if (!cm.state.completionActive) { | |
|
294 | cmLog.debug('Trigger actions hinting'); | |
|
295 | CodeMirror.showHint(cm, CodeMirror.hint.actions, options); | |
|
289 | var completeActions = function(actions){ | |
|
290 | ||
|
291 | return function(cm, pred) { | |
|
292 | var cur = cm.getCursor(); | |
|
293 | var options = { | |
|
294 | closeOnUnfocus: true | |
|
295 | }; | |
|
296 | setTimeout(function() { | |
|
297 | if (!cm.state.completionActive) { | |
|
298 | cmLog.debug('Trigger actions hinting'); | |
|
299 | CodeMirror.showHint(cm, CodeMirror.hint.actions, options); | |
|
300 | } | |
|
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; | |
|
296 | 306 | } |
|
297 | }, 100); | |
|
298 | 307 | }; |
|
299 | 308 | |
|
300 | 309 | var extraKeys = { |
@@ -314,7 +323,8 b' var initCommentBoxCodeMirror = function(' | |||
|
314 | 323 | } |
|
315 | 324 | |
|
316 | 325 | if (triggerActions) { |
|
317 | extraKeys["Ctrl-Space"] = completeActions; | |
|
326 | // register triggerActions for this instance | |
|
327 | extraKeys["'/'"] = completeActions(triggerActions); | |
|
318 | 328 | } |
|
319 | 329 | |
|
320 | 330 | var cm = CodeMirror.fromTextArea($(textAreaId).get(0), { |
@@ -349,15 +359,16 b' var initCommentBoxCodeMirror = function(' | |||
|
349 | 359 | var cur = editor.getCursor(); |
|
350 | 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 | 365 | var tokenStr = ''; |
|
355 | 366 | if (tokenMatch !== null && tokenMatch.length > 0){ |
|
356 |
tokenStr = tokenMatch[ |
|
|
367 | tokenStr = tokenMatch[2].strip(); | |
|
357 | 368 | } |
|
358 | 369 | |
|
359 | 370 | var context = { |
|
360 | start: cur.ch - tokenStr.length, | |
|
371 | start: (cur.ch - tokenStr.length) - 1, | |
|
361 | 372 | end: cur.ch, |
|
362 | 373 | string: tokenStr, |
|
363 | 374 | type: null |
@@ -366,6 +377,7 b' var initCommentBoxCodeMirror = function(' | |||
|
366 | 377 | var actions = [ |
|
367 | 378 | { |
|
368 | 379 | text: "approve", |
|
380 | searchText: "status approved", | |
|
369 | 381 | displayText: _gettext('Set status to Approved'), |
|
370 | 382 | hint: function(CodeMirror, data, completion) { |
|
371 | 383 | CodeMirror.replaceRange("", completion.from || data.from, |
@@ -384,6 +396,7 b' var initCommentBoxCodeMirror = function(' | |||
|
384 | 396 | }, |
|
385 | 397 | { |
|
386 | 398 | text: "reject", |
|
399 | searchText: "status rejected", | |
|
387 | 400 | displayText: _gettext('Set status to Rejected'), |
|
388 | 401 | hint: function(CodeMirror, data, completion) { |
|
389 | 402 | CodeMirror.replaceRange("", completion.from || data.from, |
@@ -399,6 +412,44 b' var initCommentBoxCodeMirror = function(' | |||
|
399 | 412 | el.innerHTML = completion.displayText; |
|
400 | 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 | 458 | from: CodeMirror.Pos(cur.line, context.start), |
|
408 | 459 | to: CodeMirror.Pos(cur.line, context.end) |
|
409 | 460 | }; |
|
461 | ||
|
410 | 462 | }; |
|
411 | 463 | CodeMirror.registerHelper("hint", "mentions", CodeMirrorMentionHint); |
|
412 | 464 | CodeMirror.registerHelper("hint", "actions", actionHint); |
General Comments 0
You need to be logged in to leave comments.
Login now