Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double actions in Text Editor #2656

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/robotide/editor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ def f(event):
if IS_WINDOWS or IS_MAC: # Linux does not need this key binding
self.register_shortcut('CtrlCmd-V', focused(lambda e: self._editor.paste()))
self.register_shortcut('CtrlCmd-S', focused(lambda e: self.on_saving(e)))
self.register_shortcut('CtrlCmd-F', lambda e: self._editor.search_field.SetFocus())
self.register_shortcut('CtrlCmd-G', lambda e: self._editor.on_find(e))
self.register_shortcut('CtrlCmd-Shift-G', lambda e: self._editor.on_find_backwards(e))
self.register_shortcut('CtrlCmd-F', focused(lambda e: self._editor.search_field.SetFocus()))
# To avoid double actions these moved to on_key_down
# self.register_shortcut('CtrlCmd-G', focused(lambda e: self._editor.on_find(e)))
# self.register_shortcut('CtrlCmd-Shift-G', focused(lambda e: self._editor.on_find_backwards(e)))
self.register_shortcut('Ctrl-Space', lambda e: focused(self._editor.on_content_assist(e)))
self.register_shortcut('CtrlCmd-Space', lambda e: focused(self._editor.on_content_assist(e)))
self.register_shortcut('Alt-Space', lambda e: focused(self._editor.on_content_assist(e)))
Expand Down Expand Up @@ -388,6 +389,7 @@ def __init__(self, plugin, parent, title, data_validator):
self._data_validator.set_editor(self)
self.source_editor_parent = parent
self.plugin = plugin
self.datafile = None
self._title = title
self.tab_size = self.source_editor_parent.app.settings.get(TXT_NUM_SPACES, 4)
self.reformat = self.source_editor_parent.app.settings.get('reformat', False)
Expand Down Expand Up @@ -537,11 +539,11 @@ def dirty(self):
def datafile_controller(self):
return self._data.wrapper_data if self._data else None

def on_find(self, event):
def on_find(self, event, forward=True):
if self.source_editor:
text = self.source_editor.GetSelectedText()
if len(text) > 0 and text.lower() != self.search_field.GetValue().lower() and \
event.GetEventType() == wx.wxEVT_TOOL:
if (len(text) > 0 and text.lower() != self.search_field.GetValue().lower() and
event.GetEventType() != wx.wxEVT_TOOL):
# if a search string selected in text and CTRL+G is pressed
# put the string into the search_field
self.search_field.SelectAll()
Expand All @@ -550,17 +552,16 @@ def on_find(self, event):
self.search_field.SetValue(text)
self.search_field.SelectAll()
self.search_field.Update()
# and set the start position to the beginning of the editor
self.source_editor.SetAnchor(0)
self.source_editor.SetCurrentPos(0)
self.source_editor.Update()

self._find()
if forward:
# and set the start position to the beginning of the editor
self.source_editor.SetAnchor(0)
self.source_editor.SetCurrentPos(0)
self.source_editor.Update()
self._find(forward)

def on_find_backwards(self, event):
_ = event
if self.source_editor:
self._find(forward=False)
self.on_find(event, forward=False)

def _find(self, forward=True):
txt = self.search_field.GetValue().encode('utf-8')
Expand Down Expand Up @@ -667,6 +668,8 @@ def open(self, data):
except IndexError: # It is a new project, no content yet
self._controller_for_context = DummyController(self._data.wrapper_data, self._data.wrapper_data)
self._suggestions = SuggestionSource(None, self._controller_for_context)
if self.plugin.datafile:
self.datafile = self.plugin.datafile
if not self.source_editor:
self._stored_text = self._data.content
else:
Expand Down Expand Up @@ -929,8 +932,10 @@ def paste(self):
focus = wx.Window.FindFocus()
if focus == self.source_editor:
self.source_editor.Paste()
""" DEBUG: It was double pasting in search_field
elif focus == self.search_field:
self.search_field.Paste()
"""
self._mark_file_dirty(self.source_editor.GetModify())

def select_all(self):
Expand Down Expand Up @@ -1059,6 +1064,12 @@ def on_key_down(self, event):
and event.ControlDown() and not event.ShiftDown()):
# We need to ignore this in Linux, because it does double-action
return
elif keycode in (ord('g'), ord('G')) and event.ControlDown():
if event.ShiftDown():
wx.CallAfter(self.on_find_backwards, event)
else:
wx.CallAfter(self.on_find, event)
return
elif keycode in (ord('d'), ord('D')) and event.ControlDown() and not event.ShiftDown():
# We need to ignore because Scintilla does Duplicate line
return
Expand Down Expand Up @@ -1124,7 +1135,7 @@ def _start_kw_doc_timer(self):

def execute_variable_creator(self, list_variable=False, dict_variable=False):
from_, to_ = self.source_editor.GetSelection()
text = self.source_editor.SelectedText
text = self.source_editor.GetSelectedText()
size = len(bytes(text, encoding='utf-8'))
to_ = from_ + size
if list_variable:
Expand All @@ -1151,7 +1162,7 @@ def _variable_creator_value(symbol, value=''):

def execute_enclose_text(self, keycode):
from_, to_ = self.source_editor.GetSelection()
text = self.source_editor.SelectedText
text = self.source_editor.GetSelectedText()
size = len(bytes(text, encoding='utf-8'))
to_ = from_ + size
if size == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/robotide/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#
# Automatically generated by `tasks.py`.
VERSION = 'v2.0.8dev20'
VERSION = 'v2.0.8dev21'