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

PR: Remove common prefix from path completions #361

Merged
merged 3 commits into from
Mar 2, 2020
Merged
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
26 changes: 20 additions & 6 deletions qtconsole/completion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,30 @@ def show_items(self, cursor, items, prefix_length=0):
text_edit = self._text_edit
point = self._get_top_left_position(cursor)
self.clear()
path_items = []
for item in items:
# Check if the item could refer to a file or dir. The replacing
# of '"' is needed for items on Windows
if (os.path.isfile(os.path.abspath(item.replace("\"", ""))) or
os.path.isdir(os.path.abspath(item.replace("\"", "")))):
path_items.append(item.replace("\"", ""))
else:
list_item = QtWidgets.QListWidgetItem()
list_item.setData(QtCore.Qt.UserRole, item)
list_item.setText(item.split('.')[-1])
self.addItem(list_item)

common_prefix = os.path.dirname(os.path.commonprefix(path_items))
for path_item in path_items:
list_item = QtWidgets.QListWidgetItem()
list_item.setData(QtCore.Qt.UserRole, item)
# Check if the item could refer to a file. The replacing of '"'
# is needed for items on Windows
if os.path.isfile(os.path.abspath(item.replace("\"", ""))):
list_item.setText(item)
list_item.setData(QtCore.Qt.UserRole, path_item)
if common_prefix:
text = path_item.split(common_prefix)[-1]
else:
list_item.setText(item.replace("\"", "").split('.')[-1])
text = item
list_item.setText(text)
self.addItem(list_item)

height = self.sizeHint().height()
screen_rect = QtWidgets.QApplication.desktop().availableGeometry(self)
if (screen_rect.size().height() + screen_rect.y() -
Expand Down