@@ -253,6 +253,19 @@ define(function (require, exports, module) {
253253 function _makeMRUListEntry ( file , paneId ) {
254254 return { file : file , paneId : paneId } ;
255255 }
256+
257+ /**
258+ * Locates the first MRU entry of a file
259+ * @param {!File } File - the file
260+ * @return {{file:File, paneId:string} }
261+ * @private
262+ */
263+ function _findFileInMRUList ( file ) {
264+ return _ . findIndex ( _mruList , function ( record ) {
265+ return ( record . file . fullPath === file . fullPath ) ;
266+ } ) ;
267+ }
268+
256269
257270 /**
258271 * Retrieves the currently active Pane Id
@@ -321,15 +334,21 @@ define(function (require, exports, module) {
321334 pane . makeViewMostRecent ( file ) ;
322335
323336 index = _ . findIndex ( _mruList , function ( record ) {
324- return ( record . file === file && record . paneId === paneId ) ;
337+ return ( record . file === file && record . paneId === pane . id ) ;
325338 } ) ;
326339
327340 entry = _makeMRUListEntry ( file , pane . id ) ;
328341
329342 if ( index !== - 1 ) {
330343 _mruList . splice ( index , 1 ) ;
331- _mruList . unshift ( entry ) ;
332344 }
345+
346+ if ( _findFileInMRUList ( file ) !== - 1 ) {
347+ console . log ( file . fullPath + " duplicated in mru list" ) ;
348+ }
349+
350+ // add it to the front of the list
351+ _mruList . unshift ( entry ) ;
333352 }
334353 }
335354
@@ -709,11 +728,13 @@ define(function (require, exports, module) {
709728 } else if ( result === pane . ITEM_NOT_FOUND ) {
710729 index = pane . addToViewList ( file , index ) ;
711730
712- // Add to or update the position in MRU
713- if ( pane . getCurrentlyViewedFile ( ) === file ) {
714- _mruList . unshift ( entry ) ;
715- } else {
716- _mruList . push ( entry ) ;
731+ if ( _findFileInMRUList ( file ) === - 1 ) {
732+ // Add to or update the position in MRU
733+ if ( pane . getCurrentlyViewedFile ( ) === file ) {
734+ _mruList . unshift ( entry ) ;
735+ } else {
736+ _mruList . push ( entry ) ;
737+ }
717738 }
718739
719740 exports . trigger ( "workingSetAdd" , file , index , pane . id ) ;
@@ -732,6 +753,9 @@ define(function (require, exports, module) {
732753 uniqueFileList = pane . addListToViewList ( fileList ) ;
733754
734755 uniqueFileList . forEach ( function ( file ) {
756+ if ( _findFileInMRUList ( file ) !== - 1 ) {
757+ console . log ( file . fullPath + " duplicated in mru list" ) ;
758+ }
735759 _mruList . push ( _makeMRUListEntry ( file , pane . id ) ) ;
736760 } ) ;
737761
@@ -1060,6 +1084,9 @@ define(function (require, exports, module) {
10601084 newPane . id ) ;
10611085 }
10621086 } ) ;
1087+ $ ( newPane ) . on ( "viewDestroy.mainView" , function ( e , view ) {
1088+ _removeFileFromMRU ( newPane . id , view . getFile ( ) ) ;
1089+ } ) ;
10631090 }
10641091
10651092 return newPane ;
@@ -1253,6 +1280,10 @@ define(function (require, exports, module) {
12531280 } ) ;
12541281 }
12551282
1283+ result . done ( function ( ) {
1284+ _makeFileMostRecent ( paneId , file ) ;
1285+ } ) ;
1286+
12561287 return result ;
12571288 }
12581289
@@ -1499,6 +1530,9 @@ define(function (require, exports, module) {
14991530 var fileList = pane . getViewList ( ) ;
15001531
15011532 fileList . forEach ( function ( file ) {
1533+ if ( _findFileInMRUList ( file ) !== - 1 ) {
1534+ console . log ( file . fullPath + " duplicated in mru list" ) ;
1535+ }
15021536 _mruList . push ( _makeMRUListEntry ( file , pane . id ) ) ;
15031537 } ) ;
15041538 exports . trigger ( "workingSetAddList" , fileList , pane . id ) ;
0 commit comments