summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 04:12:01 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 04:12:01 +0000
commitbf27ecfccc7cd7ef245aca4cc09262100f68db21 (patch)
tree96ca2802df0e5ea274e0846540303278fac6814d /chrome/browser
parent8b9408db240d931af213e424115b60a5fd788e3a (diff)
downloadchromium_src-bf27ecfccc7cd7ef245aca4cc09262100f68db21.zip
chromium_src-bf27ecfccc7cd7ef245aca4cc09262100f68db21.tar.gz
chromium_src-bf27ecfccc7cd7ef245aca4cc09262100f68db21.tar.bz2
Fix behaviors of Add and Remove buttons.
When a languge is added, select the newly added language. When a language is removed, keep the same position if possible. Along the way, remove unnecesary code from removeSelectedLanguage(). TEST=manually BUG=chromium-os:4573 Review URL: http://codereview.chromium.org/2878079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/resources/options/chromeos_language_list.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js
index ac0c8b9..c6e6033 100644
--- a/chrome/browser/resources/options/chromeos_language_list.js
+++ b/chrome/browser/resources/options/chromeos_language_list.js
@@ -62,8 +62,9 @@ cr.define('options.language', function() {
* @param {string} languageCode language code (ex. "fr").
*/
addLanguage: function(languageCode) {
- var dataModel = this.dataModel;
- dataModel.push(languageCode);
+ this.dataModel.push(languageCode);
+ // Select the last item, which is the language added.
+ this.selectionModel.selectedIndex = this.dataModel.length - 1;
this.updateBackend_();
},
@@ -101,8 +102,6 @@ cr.define('options.language', function() {
this.selectionModel.selectedIndex = Math.min(
originalIndex,
this.dataModel.length - 1);
- var newLanguageCodes = this.dataModel.slice();
- this.load_(newLanguageCodes);
this.updateBackend_();
}
},
@@ -125,12 +124,22 @@ cr.define('options.language', function() {
* @private
*/
load_: function(languageCodes) {
+ // Preserve the original selected index. See comments below.
+ var originalSelectedIndex = (this.selectionModel ?
+ this.selectionModel.selectedIndex : -1);
this.dataModel = new ArrayDataModel(languageCodes);
- // Select the first item if it's not empty.
- // TODO(satorux): Switch to a single item selection model that does
- // not allow no selection, one it's ready: crbug.com/49893
- if (this.dataModel.length > 0)
+ if (originalSelectedIndex >= 0 &&
+ originalSelectedIndex < this.dataModel.length) {
+ // Restore the original selected index if the selected index is
+ // valid after the data model is loaded. This is neeeded to keep
+ // the selected language after the languge is added or removed.
+ this.selectionModel.selectedIndex = originalSelectedIndex;
+ } else if (this.dataModel.length > 0){
+ // Otherwise, select the first item if it's not empty.
+ // TODO(satorux): Switch to a single item selection model that does
+ // not allow no selection, one it's ready: crbug.com/49893
this.selectionModel.selectedIndex = 0;
+ }
},
/**