| 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, |
| 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 * @private |
| 40 * @param {string} value |
| 41 * @return {boolean} true if value is empty, false otherwise. |
| 42 */ |
| 43 validateWord_: function(value) { |
| 44 return !!value.trim(); |
| 45 }, |
| 46 |
| 47 /** |
| 35 * Handles updates to the word list. Additions triggered by this element are | 48 * 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 | 49 * 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. | 50 * instead of re-sorting the list so it's clear what words were added. |
| 38 * @param {!Array<string>} added | 51 * @param {!Array<string>} added |
| 39 * @param {!Array<string>} removed | 52 * @param {!Array<string>} removed |
| 40 */ | 53 */ |
| 41 onCustomDictionaryChanged_: function(added, removed) { | 54 onCustomDictionaryChanged_: function(added, removed) { |
| 42 for (var i = 0; i < removed.length; i++) | 55 for (var i = 0; i < removed.length; i++) |
| 43 this.arrayDelete('words_', removed[i]); | 56 this.arrayDelete('words_', removed[i]); |
| 44 | 57 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 75 chrome.languageSettingsPrivate.removeSpellcheckWord(e.model.item); | 88 chrome.languageSettingsPrivate.removeSpellcheckWord(e.model.item); |
| 76 this.arrayDelete('words_', e.model.item); | 89 this.arrayDelete('words_', e.model.item); |
| 77 }, | 90 }, |
| 78 | 91 |
| 79 /** | 92 /** |
| 80 * Adds the word in the paper-input to the dictionary, also appending it | 93 * 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. | 94 * to the end of the list of words shown to the user. |
| 82 */ | 95 */ |
| 83 addWordFromInput_: function() { | 96 addWordFromInput_: function() { |
| 84 // Spaces are allowed, but removing leading and trailing whitespace. | 97 // Spaces are allowed, but removing leading and trailing whitespace. |
| 85 var word = this.$.newWord.value.trim(); | 98 var word = this.newWordValue_.trim(); |
| 86 this.$.newWord.value = ''; | 99 this.newWordValue_ = ''; |
| 87 if (!word) | 100 if (!word) |
| 88 return; | 101 return; |
| 89 | 102 |
| 90 var index = this.words_.indexOf(word); | 103 var index = this.words_.indexOf(word); |
| 91 if (index == -1) { | 104 if (index == -1) { |
| 92 chrome.languageSettingsPrivate.addSpellcheckWord(word); | 105 chrome.languageSettingsPrivate.addSpellcheckWord(word); |
| 93 this.push('words_', word); | 106 this.push('words_', word); |
| 94 } | 107 } |
| 95 | 108 |
| 96 // Scroll to the word (usually the bottom, or to the index if the word | 109 // Scroll to the word (usually the bottom, or to the index if the word |
| 97 // is already present). | 110 // is already present). |
| 98 this.$.list.scrollToIndex(index); | 111 this.$.list.scrollToIndex(index); |
| 99 }, | 112 }, |
| 100 }); | 113 }); |
| OLD | NEW |