Skip to content

Commit 8b0dcb3

Browse files
Improve auto-suggestions in Grid and Text Editors (#2589)
1 parent 69fe934 commit 8b0dcb3

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

CHANGELOG.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ All notable changes to this project will be documented in this file.
66
The format is based on http://keepachangelog.com/en/1.0.0/[Keep a Changelog]
77
and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioning].
88

9-
// == https://github.com/robotframework/RIDE[Unreleased]
9+
== https://github.com/robotframework/RIDE[Unreleased]
10+
11+
=== Changed
12+
13+
- Improve auto-suggestions of keywords in Grid Editor by allowing to close suggestions list with keys ARROW_LEFT or ARROW_RIGHT
14+
- Improve Text Editor auto-suggestions by using: selected text, text at left or at right of cursor
1015

1116
== https://github.com/robotframework/RIDE/blob/master/doc/releasenotes/ride-2.0.5.rst[2.0.5] - 2023-05-08
1217

src/robotide/editor/contentassist.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def OnKeyDown(self, event):
9090
# Ctrl-Space handling needed for dialogs # DEBUG add Ctrl-m
9191
if (control_down or alt_down) and key_code in [wx.WXK_SPACE, ord('m')]:
9292
self.show_content_assist()
93+
elif key_code in (wx.WXK_RIGHT, wx.WXK_LEFT): # To skip list and continue editing
94+
if self._popup.is_shown():
95+
value = self.GetValue()
96+
if value:
97+
self.SetValue(value)
98+
self.SetInsertionPoint(len(value))
99+
self._popup.hide()
100+
self.reset()
101+
else:
102+
event.Skip()
93103
elif key_code == wx.WXK_RETURN and self._popup.is_shown():
94104
self.OnFocusLost(event)
95105
elif key_code == wx.WXK_TAB:
@@ -493,8 +503,8 @@ def __init__(self, parent, suggestion_source):
493503
self._details_popup = HtmlPopupWindow(parent, _PREFERRED_POPUP_SIZE)
494504
self._selection = -1
495505
self._list: ContentAssistList = ContentAssistList(self._main_popup,
496-
self.OnListItemSelected,
497-
self.OnListItemActivated)
506+
self.on_list_item_selected,
507+
self.on_list_item_activated)
498508
self._suggestions = Suggestions(suggestion_source)
499509
self._choices = None
500510

@@ -586,11 +596,11 @@ def hide(self):
586596
self._main_popup.Show(False)
587597
self._details_popup.Show(False)
588598

589-
def OnListItemActivated(self, event):
599+
def on_list_item_activated(self, event):
590600
_ = event
591601
self._parent.fill_suggestion()
592602

593-
def OnListItemSelected(self, event):
603+
def on_list_item_selected(self, event):
594604
self._selection = event.GetIndex()
595605
item = self._suggestions.get_item(event.GetText())
596606
if item.details:

src/robotide/editor/texteditor.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,12 @@ def show_help_dialog(event):
501501
HtmlDialog("Getting syntax colorization", content).Show()
502502

503503
def store_position(self, force=False):
504-
_ = force
505504
if self.source_editor and self.datafile_controller:
506505
cur_pos = self.source_editor.GetCurrentPos()
507506
if cur_pos > 0: # Cheating because it always goes to zero
508507
self._position = cur_pos
509-
self.source_editor.GotoPos(self._position)
508+
if force:
509+
self.source_editor.GotoPos(self._position)
510510

511511
def set_editor_caret_position(self):
512512
if not self.is_focused(): # DEBUG was typing text when at Grid Editor
@@ -587,9 +587,9 @@ def _show_search_results(self, position, txt):
587587

588588
def OnContentAssist(self, event):
589589
_ = event
590-
self._showing_list = False
591-
# if not self.is_focused():
592-
# return
590+
if self._showing_list:
591+
self._showing_list = False # Avoid double calls
592+
return
593593
self.store_position()
594594
selected = self.source_editor.get_selected_or_near_text()
595595
sugs = [s.name for s in self._suggestions.get_suggestions(
@@ -599,6 +599,8 @@ def OnContentAssist(self, event):
599599
self.source_editor.AutoCompSetSeparator(ord(';'))
600600
self.source_editor.AutoCompShow(0, ";".join(sugs))
601601
self._showing_list = True
602+
else:
603+
self.source_editor.SetInsertionPoint(self._position) # We should know if list was canceled or value change
602604

603605
def open(self, data):
604606
self.reset()
@@ -1500,25 +1502,29 @@ def calc_margin_width(self):
15001502
def get_selected_or_near_text(self):
15011503
# First get selected text
15021504
selected = self.GetSelectedText()
1503-
self.SetInsertionPoint(self.GetInsertionPoint() - len(selected))
15041505
if selected:
1506+
self.SetInsertionPoint(self.GetSelectionStart())
15051507
return selected
15061508
# Next get text on the left
1507-
self.SetSelectionEnd(self.GetInsertionPoint())
1509+
cur_pos = self.GetInsertionPoint()
15081510
self.WordLeftEndExtend()
15091511
selected = self.GetSelectedText()
1510-
select = selected.strip()
1511-
self.SetInsertionPoint(self.GetInsertionPoint() + len(selected)
1512-
- len(select))
1512+
select = selected.lstrip()
15131513
if select and len(select) > 0:
1514+
start_pos = cur_pos - len(select)
1515+
self.SetInsertionPoint(start_pos)
1516+
self.SetSelectionStart(start_pos)
1517+
self.SetSelectionEnd(cur_pos - len(select))
15141518
return select
15151519
# Finally get text on the right
1516-
self.SetSelectionStart(self.GetInsertionPoint())
1520+
cur_pos = self.GetInsertionPoint()
1521+
self.SetSelectionStart(cur_pos)
15171522
self.WordRightEndExtend()
15181523
selected = self.GetSelectedText()
15191524
select = selected.strip()
1520-
self.SetInsertionPoint(self.GetInsertionPoint() - len(select))
15211525
if select and len(select) > 0:
1526+
cur_pos = self.GetInsertionPoint()
1527+
self.SetInsertionPoint(cur_pos - len(select))
15221528
return select
15231529

15241530

src/robotide/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515
#
1616
# Automatically generated by `tasks.py`.
17-
VERSION = 'v2.0.5'
17+
VERSION = 'v2.0.6dev1'

0 commit comments

Comments
 (0)