Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/resources/options/language_list.js

Issue 9705015: Making the selectedIndex property setters of ListSelectionModel and ListSingleSelectionModel behave… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/shared/js/cr/ui/list_selection_model.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('options', function() { 5 cr.define('options', function() {
6 const ArrayDataModel = cr.ui.ArrayDataModel; 6 const ArrayDataModel = cr.ui.ArrayDataModel;
7 const DeletableItem = options.DeletableItem; 7 const DeletableItem = options.DeletableItem;
8 const DeletableItemList = options.DeletableItemList; 8 const DeletableItemList = options.DeletableItemList;
9 const List = cr.ui.List; 9 const List = cr.ui.List;
10 const ListItem = cr.ui.ListItem; 10 const ListItem = cr.ui.ListItem;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // Preserve the original selected index. See comments below. 398 // Preserve the original selected index. See comments below.
399 var originalSelectedIndex = (this.selectionModel ? 399 var originalSelectedIndex = (this.selectionModel ?
400 this.selectionModel.selectedIndex : -1); 400 this.selectionModel.selectedIndex : -1);
401 this.dataModel = new ArrayDataModel(languageCodes); 401 this.dataModel = new ArrayDataModel(languageCodes);
402 if (originalSelectedIndex >= 0 && 402 if (originalSelectedIndex >= 0 &&
403 originalSelectedIndex < this.dataModel.length) { 403 originalSelectedIndex < this.dataModel.length) {
404 // Restore the original selected index if the selected index is 404 // Restore the original selected index if the selected index is
405 // valid after the data model is loaded. This is neeeded to keep 405 // valid after the data model is loaded. This is neeeded to keep
406 // the selected language after the languge is added or removed. 406 // the selected language after the languge is added or removed.
407 this.selectionModel.selectedIndex = originalSelectedIndex; 407 this.selectionModel.selectedIndex = originalSelectedIndex;
408 // The lead index should be updated too.
409 this.selectionModel.leadIndex = originalSelectedIndex;
410 } else if (this.dataModel.length > 0){ 408 } else if (this.dataModel.length > 0){
411 // Otherwise, select the first item if it's not empty. 409 // Otherwise, select the first item if it's not empty.
412 // Note that ListSingleSelectionModel won't select an item 410 // Note that ListSingleSelectionModel won't select an item
413 // automatically, hence we manually select the first item here. 411 // automatically, hence we manually select the first item here.
414 this.selectionModel.selectedIndex = 0; 412 this.selectionModel.selectedIndex = 0;
415 } 413 }
416 }, 414 },
417 415
418 /** 416 /**
419 * Saves the preference. 417 * Saves the preference.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 476 }
479 return filteredLanguageCodes; 477 return filteredLanguageCodes;
480 }, 478 },
481 }; 479 };
482 480
483 return { 481 return {
484 LanguageList: LanguageList, 482 LanguageList: LanguageList,
485 LanguageListItem: LanguageListItem 483 LanguageListItem: LanguageListItem
486 }; 484 };
487 }); 485 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/shared/js/cr/ui/list_selection_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698