From 37cd9d2f912c6df9b7ae7616f2fa53caafd6608d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 27 May 2019 20:57:26 +0900 Subject: Set default engine and remain last engine on form settings --- src/settings/components/form/SearchForm.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/settings/components/form') diff --git a/src/settings/components/form/SearchForm.tsx b/src/settings/components/form/SearchForm.tsx index cf78a69..6ba6cfb 100644 --- a/src/settings/components/form/SearchForm.tsx +++ b/src/settings/components/form/SearchForm.tsx @@ -54,6 +54,7 @@ class SearchForm extends React.Component { ; } + // eslint-disable-next-line max-statements bindValue(e: any) { let value = this.props.value.toJSON(); let name = e.target.name; @@ -72,8 +73,12 @@ class SearchForm extends React.Component { next.default = value.engines[index][0]; } else if (name === 'add') { next.engines.push(['', '']); - } else if (name === 'delete') { + } else if (name === 'delete' && value.engines.length > 1) { next.engines.splice(index, 1); + if (value.engines[index][0] === value.default) { + let nextIndex = Math.min(index, next.engines.length - 1); + next.default = next.engines[nextIndex][0]; + } } this.props.onChange(FormSearch.valueOf(next)); -- cgit v1.2.3