Skip to content

Commit

Permalink
Merge pull request #671 from lliehu/fix-chinese-input
Browse files Browse the repository at this point in the history
Enable using location search with shorter place names
  • Loading branch information
jake-low authored Sep 26, 2024
2 parents 646874a + 13a4e4f commit 0cfa383
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/filters/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class LocationSelect extends React.PureComponent {
};

getAsyncOptions = (input: string, cb: (e: ?Error, any) => void) => {
if (input.length >= 3) {
if (input.length >= 2 || this.isOneCharInputAllowed(input)) {
return nominatimSearch(input, this.state.queryType)
.then(json => {
if (!Array.isArray(json)) return cb(null, { options: [] });
Expand All @@ -165,6 +165,18 @@ export class LocationSelect extends React.PureComponent {
return cb(null, { options: [] });
}
};
isOneCharInputAllowed = (input: string) => {
// Allowing one character input if it contains characters from certain scripts while
// guarding against browsers that don't support this kind of regular expression
try {
return /\p{scx=Han}|\p{scx=Hangul}|\p{scx=Hiragana}|\p{scx=Katakana}/u.test(
input
);
} catch {
// Allowing always is better than never allowing for the above-mentioned scripts
return true;
}
};
onChangeLocal = (data: ?Array<Object>) => {
if (data) {
this.draw.deleteAll();
Expand Down

0 comments on commit 0cfa383

Please sign in to comment.