@@ -5064,30 +5064,41 @@ ol.control.Search = class olcontrolSearch extends ol.control.Control {
5064
5064
// move up/down
5065
5065
if (e.key == 'ArrowDown' || e.key == 'ArrowUp' || e.key == 'Down' || e.key == 'Up') {
5066
5066
if (li) {
5067
- li.classList.remove("select");
5068
- li = (/Down/.test(e.key)) ? li.nextElementSibling : li.previousElementSibling;
5069
- if (li)
5070
- li.classList.add("select");
5067
+ var newli = (/Down/.test(e.key)) ? li.nextElementSibling : li.previousElementSibling;
5068
+ if (newli && !newli.classList.contains('copy')) {
5069
+ li.classList.remove("select");
5070
+ newli.classList.add("select");
5071
+ input.value = newli.innerText;
5072
+ }
5071
5073
} else {
5072
- element.querySelector("ul.autocomplete li").classList.add("select");
5074
+ li = element.querySelector("ul.autocomplete li")
5075
+ li.classList.add("select");
5076
+ input.value = li.innerText;
5073
5077
}
5074
5078
}
5075
5079
// Clear input
5076
- else if (e.type == 'input' && !val) {
5077
- setTimeout(function () {
5078
- self.drawList_();
5079
- }, 200);
5080
+ else if (e.type == 'input') {
5081
+ if (!val) {
5082
+ setTimeout(function () {
5083
+ self.drawList_();
5084
+ }, 200);
5085
+ }
5086
+ if (li) {
5087
+ input.value = val = '';
5088
+ li.classList.remove("select");
5089
+ }
5080
5090
}
5081
5091
// Select in the list
5082
- else if (li && (e.type == "search" || e.key == "Enter")) {
5083
- if (element.classList.contains("ol-control"))
5092
+ else if (li && (e.type === "search" || e.key = == "Enter")) {
5093
+ if (element.classList.contains("ol-control")) {
5084
5094
input.blur();
5095
+ }
5085
5096
li.classList.remove("select");
5086
5097
cur = val;
5087
5098
self._handleSelect(self._list[li.getAttribute("data-search")]);
5088
5099
}
5089
5100
// Search / autocomplete
5090
- else if ((e.type == "search" || e.key == 'Enter')
5101
+ else if ((e.type === "search" || e.key = == 'Enter')
5091
5102
|| (cur != val && options.typing >= 0)) {
5092
5103
// current search
5093
5104
cur = val;
@@ -5136,6 +5147,11 @@ ol.control.Search = class olcontrolSearch extends ol.control.Control {
5136
5147
element.classList.remove('ol-revers');
5137
5148
}
5138
5149
}.bind(this));
5150
+ input.addEventListener('keydown', function() {
5151
+ this.set('reverse', false);
5152
+ element.classList.remove('ol-collapsed');
5153
+ element.classList.remove('ol-revers');
5154
+ }.bind(this))
5139
5155
}
5140
5156
element.appendChild(input);
5141
5157
// Reverse geocode
@@ -5144,15 +5160,17 @@ ol.control.Search = class olcontrolSearch extends ol.control.Control {
5144
5160
type: 'button',
5145
5161
class: 'ol-revers',
5146
5162
title: options.reverseTitle || 'click on the map',
5147
- click: function () {
5148
- if (!this.get('reverse')) {
5149
- this.set('reverse', !this.get('reverse'));
5150
- input.focus();
5151
- element.classList.add('ol-revers');
5152
- } else {
5153
- this.set('reverse', false);
5154
- }
5155
- }.bind(this)
5163
+ on: {
5164
+ focus: function () {
5165
+ if (!this.get('reverse')) {
5166
+ this.set('reverse', !this.get('reverse'));
5167
+ input.focus();
5168
+ element.classList.add('ol-revers');
5169
+ } else {
5170
+ this.set('reverse', false);
5171
+ }
5172
+ }.bind(this)
5173
+ }
5156
5174
});
5157
5175
element.appendChild(reverse);
5158
5176
}
0 commit comments