Skip to content

Commit

Permalink
Merge 2b38bab into eaea1de
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed May 12, 2020
2 parents eaea1de + 2b38bab commit 5927d29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions qtconsole/completion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def show_items(self, cursor, items, prefix_length=0):
else:
list_item = QtWidgets.QListWidgetItem()
list_item.setData(QtCore.Qt.UserRole, item)
list_item.setText(item.split('.')[-1])
# Need to split to only show last element of a dot completion
list_item.setText(item.split(".")[-1])
self.addItem(list_item)

common_prefix = os.path.dirname(os.path.commonprefix(path_items))
Expand All @@ -126,7 +127,7 @@ def show_items(self, cursor, items, prefix_length=0):
if common_prefix:
text = path_item.split(common_prefix)[-1]
else:
text = item
text = path_item
list_item.setText(text)
self.addItem(list_item)

Expand Down
18 changes: 18 additions & 0 deletions qtconsole/tests/test_completion_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import os
import tempfile
import unittest

import pytest
Expand Down Expand Up @@ -60,3 +62,19 @@ def test_droplist_completer_mousepick(self):

self.assertEqual(self.text_edit.toPlainText(), "item1")
self.assertFalse(w.isVisible())

def test_common_path_complete(self):
with tempfile.TemporaryDirectory() as tmpdir:
items = [
os.path.join(tmpdir, "common/common1/item1"),
os.path.join(tmpdir, "common/common1/item2"),
os.path.join(tmpdir, "common/common1/item3")]
for item in items:
os.makedirs(item)
w = CompletionWidget(self.console)
w.show_items(self.text_edit.textCursor(), items)
self.assertEqual(w.currentItem().text(), '/item1')
QTest.keyClick(w, QtCore.Qt.Key_Down)
self.assertEqual(w.currentItem().text(), '/item2')
QTest.keyClick(w, QtCore.Qt.Key_Down)
self.assertEqual(w.currentItem().text(), '/item3')

0 comments on commit 5927d29

Please sign in to comment.