Skip to content

Commit 783e244

Browse files
committed
Editor: Fix file completions next to path separators on Windows
1 parent c182d9d commit 783e244

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

spyder/plugins/editor/widgets/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def insert_completion(self, completion, completion_position):
971971

972972
# Adjustments for file completions
973973
if kind == CompletionItemKind.FILE:
974-
special_chars = ['"', "'", '/']
974+
special_chars = ['"', "'", '/', '\\']
975975

976976
if any(
977977
[current_text.endswith(c) for c in special_chars]

spyder/plugins/editor/widgets/tests/test_introspection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def test_dot_completions(completions_codeeditor, qtbot):
12251225
@pytest.mark.order(1)
12261226
@pytest.mark.parametrize(
12271227
"filename", ['000_test.txt', '.hidden', 'any_file.txt', 'abc.py',
1228-
'part.0.parquet', '/home', '/usr/bin'])
1228+
'part.0.parquet', '/home', '/usr/bin', r'C:\\Users'])
12291229
def test_file_completions(filename, mock_completions_codeeditor, qtbot):
12301230
"""
12311231
Test that completions for files are handled as expected.
@@ -1256,6 +1256,9 @@ def test_file_completions(filename, mock_completions_codeeditor, qtbot):
12561256
# This checks that we can insert file completions next to a / placed at
12571257
# second-level
12581258
qtbot.keyClicks(code_editor, "'/usr/'")
1259+
elif filename == r'C:\\Users':
1260+
# This checks that we can insert file completions next to a \
1261+
qtbot.keyClicks(code_editor, r"'C:\\'")
12591262
else:
12601263
qtbot.keyClicks(code_editor, f"'{filename[0]}'")
12611264
code_editor.moveCursor(QTextCursor.PreviousCharacter)
@@ -1266,6 +1269,8 @@ def test_file_completions(filename, mock_completions_codeeditor, qtbot):
12661269
completion_text = 'home'
12671270
elif filename == '/usr/bin':
12681271
completion_text = 'bin'
1272+
elif filename == r'C:\\Users':
1273+
completion_text = 'Users'
12691274
else:
12701275
completion_text = filename
12711276

0 commit comments

Comments
 (0)