@@ -39,6 +39,8 @@ define(function (require, exports, module) {
39
39
Strings = require ( "strings" ) ,
40
40
ViewUtils = require ( "utils/ViewUtils" ) ,
41
41
FindUtils = require ( "search/FindUtils" ) ,
42
+ QuickSearchField = require ( "search/QuickSearchField" ) . QuickSearchField ,
43
+ StringUtils = require ( "utils/StringUtils" ) ,
42
44
HealthLogger = require ( "utils/HealthLogger" ) ;
43
45
44
46
/**
@@ -226,12 +228,55 @@ define(function (require, exports, module) {
226
228
$elem . attr ( "title" , oldTitle + "(" + KeyBindingManager . formatKeyDescriptor ( replaceShortcut . displayKey ) + ")" ) ;
227
229
}
228
230
} ;
231
+
232
+ function highlightMatch ( item , matchClass , rangeFilter ) {
233
+ var label = item . label || item ;
234
+ matchClass = matchClass || "quicksearch-namematch" ;
235
+
236
+ var stringRanges = item . stringRanges ;
237
+ if ( ! stringRanges ) {
238
+ // If result didn't come from stringMatch(), highlight nothing
239
+ stringRanges = [ {
240
+ text : label ,
241
+ matched : false ,
242
+ includesLastSegment : true
243
+ } ] ;
244
+ }
245
+
246
+ var displayName = "" ;
247
+ if ( item . scoreDebug ) {
248
+ var sd = item . scoreDebug ;
249
+ displayName += '<span title="sp:' + sd . special + ', m:' + sd . match +
250
+ ', ls:' + sd . lastSegment + ', b:' + sd . beginning +
251
+ ', ld:' + sd . lengthDeduction + ', c:' + sd . consecutive + ', nsos: ' +
252
+ sd . notStartingOnSpecial + ', upper: ' + sd . upper + '">(' + item . matchGoodness + ') </span>' ;
253
+ }
254
+
255
+ // Put the path pieces together, highlighting the matched parts
256
+ stringRanges . forEach ( function ( range ) {
257
+ if ( range . matched ) {
258
+ displayName += "<span class='" + matchClass + "'>" ;
259
+ }
260
+
261
+ var rangeText = rangeFilter ? rangeFilter ( range . includesLastSegment , range . text ) : range . text ;
262
+ displayName += StringUtils . breakableUrl ( rangeText ) ;
263
+
264
+ if ( range . matched ) {
265
+ displayName += "</span>" ;
266
+ }
267
+ } ) ;
268
+ return displayName ;
269
+ }
229
270
230
271
/**
231
272
* Opens the Find bar, closing any other existing Find bars.
232
273
*/
233
274
FindBar . prototype . open = function ( ) {
234
275
var self = this ;
276
+
277
+ //var searchBarHTML = "<div align='right'><input type='text' autocomplete='off' id='' placeholder='" + Strings.CMD_FIND + "\u2026' style='width: 30em'><span class=''></span></div>";
278
+ //this.modalBar = new ModalBar(searchBarHTML, true);
279
+ var searchHistory = PreferencesManager . getViewState ( "searchHistory" ) ;
235
280
236
281
// Normally, creating a new Find bar will simply cause the old one to close
237
282
// automatically. This can cause timing issues because the focus change might
@@ -262,6 +307,7 @@ define(function (require, exports, module) {
262
307
FindBar . _removeFindBar ( self ) ;
263
308
MainViewManager . focusActivePane ( ) ;
264
309
self . trigger ( "close" ) ;
310
+ self . searchField . destroy ( ) ;
265
311
} ) ;
266
312
267
313
FindBar . _addFindBar ( this ) ;
@@ -311,7 +357,7 @@ define(function (require, exports, module) {
311
357
if ( intervalId === 0 ) {
312
358
intervalId = window . setInterval ( executeSearchIfNeeded , 50 ) ;
313
359
}
314
- var searchHistory = PreferencesManager . getViewState ( "searchHistory" ) ;
360
+
315
361
var maxCount = PreferencesManager . get ( "maxSearchHistory" ) ;
316
362
if ( e . keyCode === KeyEvent . DOM_VK_RETURN ) {
317
363
e . preventDefault ( ) ;
@@ -324,7 +370,9 @@ define(function (require, exports, module) {
324
370
searchHistory . pop ( ) ;
325
371
}
326
372
}
327
- searchHistory . unshift ( $ ( '#find-what' ) . val ( ) ) ;
373
+ if ( $ ( '#find-what' ) . val ( ) ) {
374
+ searchHistory . unshift ( $ ( '#find-what' ) . val ( ) ) ;
375
+ }
328
376
PreferencesManager . setViewState ( "searchHistory" , searchHistory ) ;
329
377
lastQueriedText = self . getQueryInfo ( ) . query ;
330
378
if ( self . _options . multifile ) {
@@ -347,15 +395,15 @@ define(function (require, exports, module) {
347
395
self . trigger ( "doFind" , e . shiftKey ) ;
348
396
}
349
397
historyIndex = 0 ;
350
- } else if ( e . keyCode === KeyEvent . DOM_VK_DOWN || e . keyCode === KeyEvent . DOM_VK_UP ) {
398
+ } /* else if (e.keyCode === KeyEvent.DOM_VK_DOWN || e.keyCode === KeyEvent.DOM_VK_UP) {
351
399
if (e.keyCode === KeyEvent.DOM_VK_DOWN) {
352
400
historyIndex = (historyIndex - 1 + searchHistory.length) % searchHistory.length;
353
401
} else {
354
402
historyIndex = (historyIndex + 1 + searchHistory.length) % searchHistory.length;
355
403
}
356
404
$("#find-what").val(searchHistory[historyIndex]);
357
405
self.trigger("queryChange");
358
- }
406
+ }*/
359
407
} ) ;
360
408
361
409
if ( ! this . _options . multifile ) {
@@ -401,11 +449,54 @@ define(function (require, exports, module) {
401
449
this . showIndexingSpinner ( ) ;
402
450
}
403
451
452
+ //this.$searchField.focus();
453
+
404
454
// Set up the initial UI state.
405
455
this . _updateSearchBarFromPrefs ( ) ;
406
456
this . focusQuery ( ) ;
457
+ //setTimeout(function() {
458
+ self . showSearchHints ( searchHistory ) ;
459
+ //},0);
407
460
} ;
408
461
462
+ FindBar . prototype . showSearchHints = function ( searchHistory ) {
463
+ var self = this ;
464
+ this . $searchField = $ ( "input#find-what" ) ;
465
+ this . searchField = new QuickSearchField ( this . $searchField , {
466
+ verticalAdjust : this . $searchField . offset ( ) . top > 0 ? 0 : this . _modalBar . getRoot ( ) . outerHeight ( ) ,
467
+ maxResults : 20 ,
468
+ resultProvider : function ( query ) {
469
+ var asyncResult = new $ . Deferred ( ) ;
470
+ var filteredResults = _ . filter ( searchHistory ,
471
+ function ( s ) { return s . indexOf ( query ) !== - 1 ; }
472
+ ) ;
473
+ asyncResult . resolve ( filteredResults ) ;
474
+ return asyncResult . promise ( ) ;
475
+ } , //this._filterCallback,
476
+ formatter : function ( item , query ) {
477
+ //query = query.slice(query.indexOf("@") + 1, query.length);
478
+
479
+ var displayName = highlightMatch ( item ) ;
480
+ return "<li>" + displayName + "</li>" ;
481
+ } , //this._resultsFormatterCallback,
482
+ onCommit : function ( selectedItem , query ) {
483
+ console . log ( selectedItem ) ;
484
+ console . log ( query ) ;
485
+ if ( selectedItem ) {
486
+ $ ( "#find-what" ) . val ( selectedItem ) ;
487
+ self . trigger ( "queryChange" ) ;
488
+ } else if ( query . length ) {
489
+ self . searchField . setText ( query ) ;
490
+ }
491
+ //self.trigger("queryChange");
492
+ self . searchField . destroy ( ) ;
493
+ } ,
494
+ onHighlight : function ( selectedItem , query , explicit ) { }
495
+ //verticalAdjust: 44
496
+ } ) ;
497
+ this . searchField . setText ( $ ( "#find-what" ) . val ( ) ) ;
498
+ }
499
+
409
500
/**
410
501
* Closes this Find bar. If already closed, does nothing.
411
502
* @param {boolean } suppressAnimation If true, don't do the standard closing animation. Default false.
@@ -414,6 +505,7 @@ define(function (require, exports, module) {
414
505
if ( this . _modalBar ) {
415
506
// 1st arg = restore scroll pos; 2nd arg = no animation, since getting replaced immediately
416
507
this . _modalBar . close ( true , ! suppressAnimation ) ;
508
+ //this.searchField.destroy();
417
509
}
418
510
} ;
419
511
0 commit comments