diff --git a/spyder/app/tests/conftest.py b/spyder/app/tests/conftest.py index 1a2cecd6ef8..b048766148a 100755 --- a/spyder/app/tests/conftest.py +++ b/spyder/app/tests/conftest.py @@ -328,8 +328,10 @@ def main_window(request, tmpdir, qtbot): preload_complex_project = request.node.get_closest_marker( 'preload_complex_project') if preload_complex_project: + CONF.set('editor', 'show_class_func_dropdown', True) create_complex_project(tmpdir) else: + CONF.set('editor', 'show_class_func_dropdown', False) if not preload_project: CONF.set('project_explorer', 'current_project_path', None) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index e0a07c5a35c..f9f8c5cba78 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -4227,6 +4227,39 @@ def editors_with_info(treewidget): root_1 = treewidget.editor_items[treewidget.current_editor.get_id()] assert root_1.node.childCount() == 2 + # Check that class/function selector of cloned editor is populated + editorstack_1.set_stack_index(idx) + editor_1 = editorstack_1.get_current_editor() + editor_2 = editorstack_2.get_current_editor() + assert editor_2.is_cloned + # one class + "" entry + assert editor_2.classfuncdropdown.class_cb.count() == 2 + # one function + two methods + "" entry + assert editor_2.classfuncdropdown.method_cb.count() == 4 + assert editor_1.classfuncdropdown._data == editor_2.classfuncdropdown._data + + def get_cb_list(cb): + return [cb.itemText(i) for i in range(cb.count())] + assert get_cb_list(editor_1.classfuncdropdown.class_cb) == \ + get_cb_list(editor_2.classfuncdropdown.class_cb) + assert get_cb_list(editor_1.classfuncdropdown.method_cb) == \ + get_cb_list(editor_2.classfuncdropdown.method_cb) + + # Check that class/function selector of cloned editor is updated + with qtbot.waitSignal(editor_2.oe_proxy.sig_outline_explorer_data_changed, + timeout=5000): + editor_2.set_text('def baz(x):\n return x') + assert editor_2.is_cloned + # "" entry + assert editor_2.classfuncdropdown.class_cb.count() == 1 + # one function + "" entry + assert editor_2.classfuncdropdown.method_cb.count() == 2 + assert editor_1.classfuncdropdown._data == editor_2.classfuncdropdown._data + assert get_cb_list(editor_1.classfuncdropdown.class_cb) == \ + get_cb_list(editor_2.classfuncdropdown.class_cb) + assert get_cb_list(editor_1.classfuncdropdown.method_cb) == \ + get_cb_list(editor_2.classfuncdropdown.method_cb) + # Hide outline from view outline_explorer.toggle_view_action.setChecked(False) diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py index e54248413bf..bbd89a8d4ad 100644 --- a/spyder/plugins/editor/widgets/codeeditor.py +++ b/spyder/plugins/editor/widgets/codeeditor.py @@ -1228,12 +1228,7 @@ def process_symbols(self, params): """Handle symbols response.""" try: symbols = params['params'] - symbols = [] if symbols is None else symbols - - if self.classfuncdropdown.isVisible(): - self.classfuncdropdown.update_data(symbols) - else: - self.classfuncdropdown.set_data(symbols) + self._update_classfuncdropdown(symbols) if self.oe_proxy is not None: self.oe_proxy.update_outline_info(symbols) @@ -1246,6 +1241,15 @@ def process_symbols(self, params): finally: self.symbols_in_sync = True + def _update_classfuncdropdown(self, symbols): + """Update class/function dropdown.""" + symbols = [] if symbols is None else symbols + + if self.classfuncdropdown.isVisible(): + self.classfuncdropdown.update_data(symbols) + else: + self.classfuncdropdown.set_data(symbols) + # ---- LSP: Linting and didChange # ------------------------------------------------------------------------- def _schedule_document_did_change(self): diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py index 9f27ee12899..eeaf09e3811 100644 --- a/spyder/plugins/editor/widgets/editor.py +++ b/spyder/plugins/editor/widgets/editor.py @@ -2681,6 +2681,8 @@ def perform_completion_request(lang, method, params): # symbols for the clon are updated as expected. cloned_from.oe_proxy.sig_outline_explorer_data_changed.connect( editor.oe_proxy.update_outline_info) + cloned_from.oe_proxy.sig_outline_explorer_data_changed.connect( + editor._update_classfuncdropdown) cloned_from.oe_proxy.sig_start_outline_spinner.connect( editor.oe_proxy.emit_request_in_progress)