From c496bd77c0b022cf222ca3428f06efbd24073940 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 18 May 2018 11:44:14 -0600 Subject: [PATCH] Add useIpaPronunciationField option to prevent IPA transformation in pronunciation field. --- src/components/MainDisplay.jsx | 4 +++ src/components/display/WordDisplay/index.jsx | 4 ++- src/components/display/WordsList.jsx | 2 ++ src/components/management/IPAField.jsx | 30 ++++++++++++-------- src/components/management/WordForm.jsx | 2 ++ src/index.jsx | 2 ++ 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/components/MainDisplay.jsx b/src/components/MainDisplay.jsx index 28bca00..2d6266a 100644 --- a/src/components/MainDisplay.jsx +++ b/src/components/MainDisplay.jsx @@ -22,6 +22,7 @@ export class MainDisplay extends Component { wordsInCurrentList: PropTypes.number, currentPage: PropTypes.number, itemsPerPage: PropTypes.number, + useIpaPronunciationField: PropTypes.bool, stats: PropTypes.object.isRequired, setPage: PropTypes.func.isRequired, updateDisplay: PropTypes.func.isRequired, @@ -63,6 +64,7 @@ export class MainDisplay extends Component { wordsInCurrentList, currentPage, itemsPerPage, + useIpaPronunciationField, stats, setPage, updateDisplay, @@ -84,6 +86,7 @@ export class MainDisplay extends Component { closeWordForm={ this.closeWordForm.bind(this) } > @@ -121,6 +124,7 @@ export class MainDisplay extends Component { isLoadingWords={ isLoadingWords } words={ wordsToDisplay } adsEveryXWords={ 10 } + useIpaFieldOnEdit={ useIpaPronunciationField } updateDisplay={ updateDisplay } /> { this.setState({ diff --git a/src/components/display/WordsList.jsx b/src/components/display/WordsList.jsx index 058b4ad..88f0534 100644 --- a/src/components/display/WordsList.jsx +++ b/src/components/display/WordsList.jsx @@ -16,6 +16,7 @@ export class WordsList extends Component { isLoadingWords: PropTypes.bool, adsEveryXWords: PropTypes.number, words: PropTypes.array, + useIpaFieldOnEdit: PropTypes.bool, updateDisplay: PropTypes.func.isRequired, }, props, 'prop', 'WordList'); } @@ -41,6 +42,7 @@ export class WordsList extends Component { } ); diff --git a/src/components/management/IPAField.jsx b/src/components/management/IPAField.jsx index 33e8ef0..d9d9971 100644 --- a/src/components/management/IPAField.jsx +++ b/src/components/management/IPAField.jsx @@ -22,6 +22,7 @@ export class IPAField extends Component { helpText: PropTypes.string, placeholder: PropTypes.string, isDisplayOnly: PropTypes.bool, + preventIPA: PropTypes.bool, onInput: PropTypes.func, onChange: PropTypes.func, }, props, 'prop', 'IPAField'); @@ -102,23 +103,28 @@ export class IPAField extends Component { } onInput (event) { - let val = event.target.value, - pos = this.field.selectionStart || val.length; + let val = event.target.value; + let pos; + if (!this.props.preventIPA) { + pos = this.field.selectionStart || val.length; - if (event.key) { - const key = event.key, - digraph = digraphs[val.substr(pos - 1, 1) + key]; + if (event.key) { + const key = event.key, + digraph = digraphs[val.substr(pos - 1, 1) + key]; - if (digraph) { - event.preventDefault(); - val = val.slice(0, pos - 1) + digraph + val.slice(pos); + if (digraph) { + event.preventDefault(); + val = val.slice(0, pos - 1) + digraph + val.slice(pos); + } } } if (val !== this.state.value) { this.setState({ value: val }, () => { - this.field.focus(); - this.field.setSelectionRange(pos, pos); + if (!this.props.preventIPA) { + this.field.focus(); + this.field.setSelectionRange(pos, pos); + } if (this.props.onInput) { this.props.onInput(this.state.value); @@ -149,7 +155,7 @@ export class IPAField extends Component { }
this.field = input } value={ this.state.value } @@ -157,7 +163,7 @@ export class IPAField extends Component { onKeyDown={ (event) => this.onInput(event) } onChange={ () => this.onChange() } />
- { this.showButtons() } + { !this.props.preventIPA && this.showButtons() } ); } diff --git a/src/components/management/WordForm.jsx b/src/components/management/WordForm.jsx index 6feffea..c24ddcf 100644 --- a/src/components/management/WordForm.jsx +++ b/src/components/management/WordForm.jsx @@ -13,6 +13,7 @@ export class WordForm extends Component { PropTypes.checkPropTypes({ word: PropTypes.object, + useIpaField: PropTypes.bool.isRequired, callback: PropTypes.func, updateDisplay: PropTypes.func, }, props, 'prop', 'WordForm'); @@ -120,6 +121,7 @@ export class WordForm extends Component { this.setState({ wordPronunciation: newValue }) } />
diff --git a/src/index.jsx b/src/index.jsx index 5b1d345..2487427 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -38,6 +38,7 @@ class App extends Component { displayedWords: [], currentPage: 0, itemsPerPage: 30, + useIpaPronunciationField: true, searchConfig: { searchingIn: 'name', searchMethod: SEARCH_METHOD.contains, @@ -218,6 +219,7 @@ class App extends Component { wordsInCurrentList={ this.state.wordsInCurrentList } currentPage={ this.state.currentPage } itemsPerPage={ this.state.itemsPerPage } + useIpaPronunciationField={ this.state.useIpaPronunciationField } stats={ this.state.stats } setPage={ this.setPage.bind(this) } updateDisplay={ this.updateDisplayedWords.bind(this) }