Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
| 6 * @fileoverview 'settings-edit-dictionary-page' is a sub-page for editing | 6 * @fileoverview 'settings-edit-dictionary-page' is a sub-page for editing |
| 7 * the "dictionary" of custom words used for spell check. | 7 * the "dictionary" of custom words used for spell check. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-edit-dictionary-page', | 10 is: 'settings-edit-dictionary-page', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private {string} */ | |
| 14 newWordValue: String, | |
|
dpapad
2017/02/04 01:13:16
Nit (optional): Perhaps rename s/newWordValue/newW
scottchen
2017/02/06 18:44:01
I'm gonna keep this the same; I changed it to newW
| |
| 15 | |
| 13 /** @private {!Array<string>} */ | 16 /** @private {!Array<string>} */ |
| 14 words_: { | 17 words_: { |
| 15 type: Array, | 18 type: Array, |
| 16 value: function() { return []; }, | 19 value: function() { return []; }, |
| 17 }, | 20 }, |
| 18 }, | 21 }, |
| 19 | 22 |
| 20 ready: function() { | 23 ready: function() { |
| 21 chrome.languageSettingsPrivate.getSpellcheckWords(function(words) { | 24 chrome.languageSettingsPrivate.getSpellcheckWords(function(words) { |
| 22 this.words_ = words; | 25 this.words_ = words; |
| 23 }.bind(this)); | 26 }.bind(this)); |
| 24 | 27 |
| 25 // Updates are applied locally so they appear immediately, but we should | 28 // Updates are applied locally so they appear immediately, but we should |
| 26 // listen for changes in case they come from elsewhere. | 29 // listen for changes in case they come from elsewhere. |
| 27 chrome.languageSettingsPrivate.onCustomDictionaryChanged.addListener( | 30 chrome.languageSettingsPrivate.onCustomDictionaryChanged.addListener( |
| 28 this.onCustomDictionaryChanged_.bind(this)); | 31 this.onCustomDictionaryChanged_.bind(this)); |
| 29 | 32 |
| 30 // Add a key handler for the paper-input. | 33 // Add a key handler for the paper-input. |
| 31 this.$.keys.target = this.$.newWord; | 34 this.$.keys.target = this.$.newWord; |
| 32 }, | 35 }, |
| 33 | 36 |
| 34 /** | 37 /** |
| 38 * Check if the new word text-field is empty. | |
| 39 * @param {string} value | |
| 40 * @return {bool} true if value is empty, false otherwise. | |
|
dpapad
2017/02/04 01:13:16
This will blow up in compilation. s/bool/boolean.
scottchen
2017/02/06 18:44:01
Done.
| |
| 41 */ | |
| 42 isNewWordEmpty_: function(value) { | |
|
dpapad
2017/02/04 01:13:16
I suggest not capturing the implementation details
scottchen
2017/02/06 18:44:01
Done.
| |
| 43 return !value.trim(); | |
| 44 }, | |
| 45 | |
| 46 /** | |
| 35 * Handles updates to the word list. Additions triggered by this element are | 47 * Handles updates to the word list. Additions triggered by this element are |
| 36 * de-duped so the word list remains a set. Words are appended to the end | 48 * de-duped so the word list remains a set. Words are appended to the end |
| 37 * instead of re-sorting the list so it's clear what words were added. | 49 * instead of re-sorting the list so it's clear what words were added. |
| 38 * @param {!Array<string>} added | 50 * @param {!Array<string>} added |
| 39 * @param {!Array<string>} removed | 51 * @param {!Array<string>} removed |
| 40 */ | 52 */ |
| 41 onCustomDictionaryChanged_: function(added, removed) { | 53 onCustomDictionaryChanged_: function(added, removed) { |
| 42 for (var i = 0; i < removed.length; i++) | 54 for (var i = 0; i < removed.length; i++) |
| 43 this.arrayDelete('words_', removed[i]); | 55 this.arrayDelete('words_', removed[i]); |
| 44 | 56 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 75 chrome.languageSettingsPrivate.removeSpellcheckWord(e.model.item); | 87 chrome.languageSettingsPrivate.removeSpellcheckWord(e.model.item); |
| 76 this.arrayDelete('words_', e.model.item); | 88 this.arrayDelete('words_', e.model.item); |
| 77 }, | 89 }, |
| 78 | 90 |
| 79 /** | 91 /** |
| 80 * Adds the word in the paper-input to the dictionary, also appending it | 92 * Adds the word in the paper-input to the dictionary, also appending it |
| 81 * to the end of the list of words shown to the user. | 93 * to the end of the list of words shown to the user. |
| 82 */ | 94 */ |
| 83 addWordFromInput_: function() { | 95 addWordFromInput_: function() { |
| 84 // Spaces are allowed, but removing leading and trailing whitespace. | 96 // Spaces are allowed, but removing leading and trailing whitespace. |
| 85 var word = this.$.newWord.value.trim(); | 97 var word = this.newWordValue.trim(); |
| 86 this.$.newWord.value = ''; | 98 this.newWordValue = ''; |
| 87 if (!word) | 99 if (!word) |
| 88 return; | 100 return; |
| 89 | 101 |
| 90 var index = this.words_.indexOf(word); | 102 var index = this.words_.indexOf(word); |
| 91 if (index == -1) { | 103 if (index == -1) { |
| 92 chrome.languageSettingsPrivate.addSpellcheckWord(word); | 104 chrome.languageSettingsPrivate.addSpellcheckWord(word); |
| 93 this.push('words_', word); | 105 this.push('words_', word); |
| 94 } | 106 } |
| 95 | 107 |
| 96 // Scroll to the word (usually the bottom, or to the index if the word | 108 // Scroll to the word (usually the bottom, or to the index if the word |
| 97 // is already present). | 109 // is already present). |
| 98 this.$.list.scrollToIndex(index); | 110 this.$.list.scrollToIndex(index); |
| 99 }, | 111 }, |
| 100 }); | 112 }); |
| OLD | NEW |