|
12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
| 15 | +from operator import index |
15 | 16 |
|
16 | 17 | import wx |
17 | 18 | from wx import Colour |
@@ -262,22 +263,39 @@ def on_focus_lost(self, event, set_value=True): |
262 | 263 | event.Skip() |
263 | 264 | if not self._popup.is_shown(): |
264 | 265 | return |
265 | | - if self.gherkin_prefix: |
266 | | - value = self.gherkin_prefix + self._popup.get_value() or self.GetValue() |
267 | | - else: |
268 | | - value = self._popup.get_value() or self.GetValue() |
| 266 | + value = self._get_popup_suggestion() |
269 | 267 | if set_value and value: |
270 | 268 | self.SetValue(value) |
271 | 269 | self.SetInsertionPoint(len(value)) # DEBUG was self.Value |
272 | 270 | else: |
| 271 | + # print(f"DEBUG: contentassist.py ContentAssistTextCtrlBase on_focus_lost CALL CLEAR {value}") |
273 | 272 | self.Clear() |
274 | 273 | self.hide() |
275 | 274 |
|
276 | | - def fill_suggestion(self): |
| 275 | + def _get_popup_suggestion(self, in_value=None): |
| 276 | + initial_value = self.GetValue() |
| 277 | + if not in_value: |
| 278 | + popup_value = self._popup.get_value() |
| 279 | + else: |
| 280 | + popup_value = in_value |
| 281 | + if popup_value and popup_value.lower() in initial_value.lower(): |
| 282 | + initial_value = initial_value.replace(initial_value, '') |
| 283 | + parts = initial_value.split() |
| 284 | + for p in parts: |
| 285 | + if popup_value and popup_value.lower().startswith(p.strip('}])').lower()): |
| 286 | + idx = initial_value.index(p) |
| 287 | + initial_value = initial_value[:idx] |
| 288 | + break |
277 | 289 | if self.gherkin_prefix: |
278 | | - value = self.gherkin_prefix + self._popup.get_value() or self.GetValue() |
| 290 | + initial_value = initial_value.replace(self.gherkin_prefix, '') # Should be left replace |
| 291 | + value = self.gherkin_prefix + initial_value + popup_value # or self.GetValue() |
279 | 292 | else: |
280 | | - value = self._popup.get_value() or self.GetValue() |
| 293 | + value = initial_value + popup_value # or self.GetValue() |
| 294 | + return value |
| 295 | + |
| 296 | + def fill_suggestion(self, value=None): |
| 297 | + value = self._get_popup_suggestion(value) |
| 298 | + # print(f"DEBUG: contentassist.py ContentAssistTextCtrlBase fill_suggestion writting value={value}") |
281 | 299 | if value: |
282 | 300 | wrapper_view = self.GetParent().GetParent() |
283 | 301 | if hasattr(wrapper_view, 'open_cell_editor'): |
@@ -604,15 +622,14 @@ def select_and_scroll(self, key_code): |
604 | 622 | pos = self._selection + 14 if count - self._selection > 14 else count - 1 |
605 | 623 | elif key_code == wx.WXK_PAGEUP: |
606 | 624 | pos = self._selection - 14 if self._selection > 14 else 0 |
607 | | - self._select_and_scroll(pos) |
| 625 | + return self._select_and_scroll(pos) |
608 | 626 |
|
609 | 627 | def _select_and_scroll(self, selection): |
610 | 628 | self._selection = selection |
611 | 629 | self._list.Select(self._selection) |
612 | 630 | self._list.EnsureVisible(self._selection) |
613 | 631 | value = self.get_value() |
614 | | - if value: |
615 | | - self._parent.SetValue(value) |
| 632 | + return value |
616 | 633 |
|
617 | 634 | def dismiss(self): |
618 | 635 | if not self._list.HasFocus(): |
|
0 commit comments