Skip to content

Commit ce0509a

Browse files
Fix empty line at Variable section in Text Editor. Note: unit test not done (#2616)
1 parent fb7fc55 commit ce0509a

File tree

8 files changed

+67
-19
lines changed

8 files changed

+67
-19
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni
1616

1717
== Fixed
1818

19+
- Fixed empty line being always added to the Variables section in Text Editor
1920
- Fixed wrong project reloading when file system changes detected, and other related problems
2021
- Fixed control commands (``FOR``, ``IF``, ``TRY``, etc) being colorized as valid keywords when typed not in all caps in Grid Editor
2122
- Fixed title of User Keyword in Grid Editor always showing ``Find Usages`` instead of the keyword name

src/robotide/application/CHANGELOG.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Added sincronization with Project Explorer to navigate to selected item, Test Case, Keyword, Variable, in Text Editor
77
Note: This feature is working fine in Fedora 38, but not on Windows and macOS.
88
</li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_fixed"></a>2. Fixed</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
9+
Fixed empty line being always added to the Variables section in Text Editor
10+
</li><li class="listitem">
911
Fixed wrong project reloading when file system changes detected, and other related problems
1012
</li><li class="listitem">
1113
Fixed control commands (``FOR``, ``IF``, ``TRY``, etc) being colorized as valid keywords when typed not in all caps in Grid Editor

src/robotide/application/releasenotes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def set_content(self, html_win, content):
168168
</ul>
169169
<p><strong>New Features and Fixes Highlights</strong></p>
170170
<ul class="simple">
171+
<li>Fixed empty line being always added to the Variables section in Text Editor</li>
171172
<li>Improved project file system changes and reloading</li>
172173
<li>Added context menu to RIDE tray icon. Options Show, Hide and Close</li>
173174
<li>Added sincronization with Project Explorer to navigate to selected item, Test Case, Keyword, Variable, in Text
@@ -226,6 +227,6 @@ def set_content(self, html_win, content):
226227
<pre class="literal-block">
227228
python -m robotide.postinstall -install
228229
</pre>
229-
<p>RIDE {VERSION} was released on 09/Jul/2023.</p>
230+
<p>RIDE {VERSION} was released on 30/Jul/2023.</p>
230231
</div>
231232
"""

src/robotide/editor/texteditor.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,15 @@ def validate_and_update(self, data, text):
275275
if not handled:
276276
return False
277277
self._editor.reset()
278-
data.update_from(m_text)
279-
"""
280-
# DEBUG: This is the area where we will implement to not reformat code
281-
if self.source_editor._reformat:
282-
data.update_from(m_text)
278+
if self._editor.reformat:
279+
data.update_from(data.format_text(m_text))
283280
else:
284-
data.update_from(m_text) # TODO: This is the same code as _reformat == True
281+
# DEBUG: This is the area where we will implement to not reformat code
282+
data.update_from(m_text)
285283
# There is no way to update the model without reformatting
286-
# TODO this only updates the editor, but not the model, changes in Text Editor are not reflected in Grid or
287-
# when saving
288-
# self.source_editor.source_editor.set_text(m_text)
289-
"""
284+
# DEBUG: this only updates the editor, but not the model, changes in Text Editor are not reflected
285+
# in Grid or when saving
286+
# self.source_editor.source_editor.set_text(m_text)
290287
self._editor.set_editor_caret_position()
291288
return True
292289

@@ -397,7 +394,7 @@ def __init__(self, parent, title, data_validator):
397394
self.source_editor_parent = parent
398395
self._title = title
399396
self.tab_size = self.source_editor_parent.app.settings.get(TXT_NUM_SPACES, 4)
400-
self._reformat = self.source_editor_parent.app.settings.get('reformat', False)
397+
self.reformat = self.source_editor_parent.app.settings.get('reformat', False)
401398
self._create_ui(title)
402399
self._data = None
403400
self._dirty = 0 # 0 is False and 1 is True, when changed on this editor
@@ -1463,7 +1460,7 @@ def on_settings_changed(self, message):
14631460
if setting == TXT_NUM_SPACES:
14641461
self.tab_size = self.source_editor_parent.app.settings.get(TXT_NUM_SPACES, 4)
14651462
if setting == 'reformat':
1466-
self._reformat = self.source_editor_parent.app.settings.get('reformat', False)
1463+
self.reformat = self.source_editor_parent.app.settings.get('reformat', False)
14671464

14681465
def _mark_file_dirty(self, dirty=True):
14691466
if not self.is_focused(): # DEBUG: Was marking file clean from Grid Editor

src/robotide/lib/robot/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
VERSION = '3.1.2' # Original library version
2323
ROBOT_VERSION = getenv('ROBOT_VERSION') # Set the version from environment, like "3.1.2"
2424
if not ROBOT_VERSION:
25-
ROBOT_VERSION = (6, 0, 2) # Define here or use environmnt variable. Condition library alias with AS
25+
ROBOT_VERSION = (6, 1, 1) # Define here or use environment variable. Condition library alias with AS
2626
else:
2727
if not isinstance(ROBOT_VERSION, tuple):
2828
try:
2929
ROBOT_VERSION = tuple(int(x) for x in ROBOT_VERSION.replace(',', '.').strip('()').split('.')[:])
3030
except (TypeError, ValueError):
31-
ROBOT_VERSION = (6, 0, 2)
31+
ROBOT_VERSION = (6, 1, 1)
3232

3333
ALIAS_MARKER = 'AS' if ROBOT_VERSION >= (6, 0, 0) else 'WITH NAME'
3434

src/robotide/lib/robot/writer/filewriters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def _write_table(self, table, is_last):
5959
self._write_header(table)
6060
self._write_rows(self._formatter.format_table(table))
6161
if not is_last: # DEBUG: make this configurable
62+
# print(f"DEBUG: lib.robot.writer _DataFileWritter write_table empty_row table={table.type}")
63+
if table.type == 'variable' and len(list(table)[-1].as_list()) == 0:
64+
# DEBUG: This is workaround for newline being added ALWAYS to VariableTable
65+
return
6266
self._write_empty_row(table)
6367

6468
def _write_header(self, table):
@@ -115,7 +119,8 @@ def __init__(self, configuration):
115119
_DataFileWriter.__init__(self, formatter, configuration)
116120
self._writer = self._get_writer(configuration)
117121

118-
def _get_writer(self, configuration):
122+
@staticmethod
123+
def _get_writer(configuration):
119124
# Custom dialect needed as a workaround for
120125
# http://ironpython.codeplex.com/workitem/33627
121126
dialect = csv.excel_tab()

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.7dev7'
17+
VERSION = 'v2.0.7dev8'

utest/editor/test_texteditor.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ def setUp(self):
146146
texteditor.DataValidationHandler(self.plugin))
147147
self.plugin.enable()
148148
self.app.project.load_datafile(datafilereader.TESTCASEFILE_WITH_EVERYTHING, MessageRecordingLoadObserver())
149+
self.notebook = self.app.book
149150
self.app.tree.set_editor(self.plugin._editor_component)
150151
self.app.tree.populate(self.app.project)
152+
self.source = self.app.tree.controller
153+
self.plugin._open_tree_selection_in_editor()
151154
self.app.frame.SetStatusText("File:" + self.app.project.data.source)
152155
# Uncomment next line (and MainLoop in tests) if you want to see the app
153156
# self.frame.Show()
@@ -421,8 +424,47 @@ def test_execute_sharp_uncomment_with_selection(self):
421424
# print(f"DEBUG: fulltext:\n{fulltext}")
422425
assert fulltext == spaces + '1 - Line one' + spaces + 'with cells' + spaces + 'last text\n'
423426
# Uncomment next lines if you want to see the app
424-
wx.CallLater(5000, self.app.ExitMainLoop)
425-
self.app.MainLoop()
427+
# wx.CallLater(5000, self.app.ExitMainLoop)
428+
# self.app.MainLoop()
429+
430+
def test_check_variables_section(self):
431+
pos = len('1 - Line one\n')
432+
spaces = ' ' * self.plugin._editor_component.tab_size
433+
text = "${ARG} value" # Text to find (last item in Variable section)
434+
with open(datafilereader.TESTCASEFILE_WITH_EVERYTHING, "r") as fp: #, MessageRecordingLoadObserver())
435+
content = fp.readlines()
436+
content = "".join(content)
437+
# self.plugin.on_open(None)
438+
# datafilecontroller = self.app.tree.get_selected_datafile_controller()
439+
# print(f"DEBUG: datafilecontroller={datafilecontroller} controller={self.app.tree.controller}")
440+
# self.plugin._open_data_for_controller(self.app.tree.get_selected_datafile_controller())
441+
# self.plugin.on_open(wx.EVT_FILECTRL_SELECTIONCHANGED)
442+
# content = ['1 - Line one\n', '2 - Line two\n', '3 - Line three\n']
443+
# self.plugin._editor_component.source_editor.set_text(
444+
# content[0] + 'Comment' + spaces + content[1] + content[2])
445+
self.plugin._editor_component.source_editor.set_text(content)
446+
# self.plugin._editor_component.source_editor.SetSelection(pos + 1, pos + 4)
447+
# self.plugin._editor_component.execute_uncomment(None)
448+
self.plugin._editor_component.store_position(True)
449+
self.plugin._editor_component.set_editor_caret_position()
450+
position = self.plugin._editor_component._find_text_position(True, text)
451+
self.plugin._editor_component._show_search_results(position, text)
452+
position = self.plugin._editor_component.source_editor.GetCurrentPos()
453+
self.plugin._editor_component.source_editor.InsertText(position, "123\n\n")
454+
fulltext = self.plugin._editor_component.source_editor.GetText()
455+
# print(f"DEBUG: fulltext:\n{fulltext}")
456+
# Activate Apply to cleanup text
457+
self.plugin._editor_component._dirty = True
458+
# self.plugin._apply_txt_changes_to_model()
459+
# DEBUG: THIS IS THE TEST, IT FAILS BECAUSE WE DON'T HAVE data and controller
460+
# result = self.plugin._editor_component.save()
461+
# print(f"DEBUG: result={result} is_dirty={self.plugin._editor_component.dirty}")
462+
after_apply = self.plugin._editor_component.source_editor.GetText()
463+
print(f"DEBUG: after_apply len={len(after_apply)} initial content len={len(content)}:\n{after_apply}")
464+
# assert fulltext == content[0] + content[1] + content[2]
465+
# Uncomment next lines if you want to see the app
466+
# wx.CallLater(5000, self.app.ExitMainLoop)
467+
# self.app.MainLoop()
426468

427469

428470
if __name__ == '__main__':

0 commit comments

Comments
 (0)