Skip to content

Commit af2518c

Browse files
committed
show previous autocomplete elements
1 parent a5382eb commit af2518c

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/sidebar/search/AddressInput.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ export default function AddressInput(props: AddressInputProps) {
4242
const [hasFocus, setHasFocus] = useState(false)
4343
const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })
4444

45-
// container for geocoding results which gets set by the geocoder class and set to empty if the underlying query point gets changed from outside
46-
// also gets filled with an item to select the current location as input if input has focus and geocoding results are
47-
// empty
45+
// container for geocoding results which gets set by the geocoder class and set to empty if the underlying query
46+
// point gets changed from outside also gets filled with an item to select the current location as input if input
47+
// has focus and geocoding results are empty
48+
const [origAutocompleteItems, setOrigAutocompleteItems] = useState<AutocompleteItem[]>([])
4849
const [autocompleteItems, setAutocompleteItems] = useState<AutocompleteItem[]>([])
4950
const [geocoder] = useState(
5051
new Geocoder(getApi(), (query, provider, hits) => {
@@ -58,10 +59,6 @@ export default function AddressInput(props: AddressInputProps) {
5859
)
5960
})
6061

61-
// TODO autocompleteItems is empty here because query point changed from outside somehow
62-
// const res = autocompleteItems.length > 1 ? autocompleteItems.slice(0, autocompleteItems.length - 2) : autocompleteItems
63-
// res.concat(items)
64-
6562
setOrigText(query)
6663
setAutocompleteItems(items)
6764
})
@@ -76,6 +73,7 @@ export default function AddressInput(props: AddressInputProps) {
7673

7774
function hideSuggestions() {
7875
geocoder.cancel()
76+
setOrigAutocompleteItems(autocompleteItems)
7977
setAutocompleteItems([])
8078
}
8179

@@ -164,8 +162,6 @@ export default function AddressInput(props: AddressInputProps) {
164162
const type = props.point.type
165163

166164
// get the bias point for the geocoder
167-
// (the query point above the current one)
168-
const autocompleteIndex = props.points.findIndex(point => !point.isInitialized)
169165
const lonlat = toLonLat(getMap().getView().getCenter()!)
170166
const biasCoord = { lng: lonlat[0], lat: lonlat[1] }
171167

@@ -208,6 +204,7 @@ export default function AddressInput(props: AddressInputProps) {
208204
onFocus={() => {
209205
setHasFocus(true)
210206
props.clearDragDrop()
207+
if (origAutocompleteItems.length > 0) setAutocompleteItems(origAutocompleteItems)
211208
}}
212209
onBlur={() => {
213210
if (!isSmallScreen) hideSuggestions() // see #398

src/sidebar/search/Search.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ const SearchBox = ({
170170
onCancel={() => console.log('cancel')}
171171
onAddressSelected={(queryText, coordinate) => {
172172
const initCount = points.filter(p => p.isInitialized).length
173-
if (coordinate && initCount == 0) Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))
173+
if (coordinate && initCount != points.length)
174+
Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))
174175

175176
Dispatcher.dispatch(
176177
new SetPoint(

0 commit comments

Comments
 (0)