Merge remote-tracking branch 'origin/pr/3606'
This commit is contained in:
commit
14d6e737fa
@ -596,6 +596,8 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
if config.val.prompt.filebrowser:
|
if config.val.prompt.filebrowser:
|
||||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||||
|
|
||||||
|
self._to_complete = ''
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def _set_fileview_root(self, path, *, tabbed=False):
|
def _set_fileview_root(self, path, *, tabbed=False):
|
||||||
"""Set the root path for the file display."""
|
"""Set the root path for the file display."""
|
||||||
@ -604,6 +606,9 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
separators += os.altsep
|
separators += os.altsep
|
||||||
|
|
||||||
dirname = os.path.dirname(path)
|
dirname = os.path.dirname(path)
|
||||||
|
basename = os.path.basename(path)
|
||||||
|
if not tabbed:
|
||||||
|
self._to_complete = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not path:
|
if not path:
|
||||||
@ -617,6 +622,7 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
elif os.path.isdir(dirname) and not tabbed:
|
elif os.path.isdir(dirname) and not tabbed:
|
||||||
# Input like /foo/ba -> show /foo contents
|
# Input like /foo/ba -> show /foo contents
|
||||||
path = dirname
|
path = dirname
|
||||||
|
self._to_complete = basename
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -634,7 +640,11 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
index: The QModelIndex of the selected element.
|
index: The QModelIndex of the selected element.
|
||||||
clicked: Whether the element was clicked.
|
clicked: Whether the element was clicked.
|
||||||
"""
|
"""
|
||||||
path = os.path.normpath(self._file_model.filePath(index))
|
if index == QModelIndex():
|
||||||
|
path = os.path.join(self._file_model.rootPath(), self._to_complete)
|
||||||
|
else:
|
||||||
|
path = os.path.normpath(self._file_model.filePath(index))
|
||||||
|
|
||||||
if clicked:
|
if clicked:
|
||||||
path += os.sep
|
path += os.sep
|
||||||
else:
|
else:
|
||||||
@ -696,6 +706,7 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
assert last_index.isValid()
|
assert last_index.isValid()
|
||||||
|
|
||||||
idx = selmodel.currentIndex()
|
idx = selmodel.currentIndex()
|
||||||
|
|
||||||
if not idx.isValid():
|
if not idx.isValid():
|
||||||
# No item selected yet
|
# No item selected yet
|
||||||
idx = last_index if which == 'prev' else first_index
|
idx = last_index if which == 'prev' else first_index
|
||||||
@ -709,10 +720,24 @@ class FilenamePrompt(_BasePrompt):
|
|||||||
if not idx.isValid():
|
if not idx.isValid():
|
||||||
idx = last_index if which == 'prev' else first_index
|
idx = last_index if which == 'prev' else first_index
|
||||||
|
|
||||||
|
idx = self._do_completion(idx, which)
|
||||||
|
|
||||||
selmodel.setCurrentIndex(
|
selmodel.setCurrentIndex(
|
||||||
idx, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
|
idx, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
|
||||||
self._insert_path(idx, clicked=False)
|
self._insert_path(idx, clicked=False)
|
||||||
|
|
||||||
|
def _do_completion(self, idx, which):
|
||||||
|
filename = self._file_model.fileName(idx)
|
||||||
|
while not filename.startswith(self._to_complete) and idx.isValid():
|
||||||
|
if which == 'prev':
|
||||||
|
idx = self._file_view.indexAbove(idx)
|
||||||
|
else:
|
||||||
|
assert which == 'next', which
|
||||||
|
idx = self._file_view.indexBelow(idx)
|
||||||
|
filename = self._file_model.fileName(idx)
|
||||||
|
|
||||||
|
return idx
|
||||||
|
|
||||||
def _allowed_commands(self):
|
def _allowed_commands(self):
|
||||||
return [('prompt-accept', 'Accept'), ('leave-mode', 'Abort')]
|
return [('prompt-accept', 'Accept'), ('leave-mode', 'Abort')]
|
||||||
|
|
||||||
|
@ -81,6 +81,14 @@ class TestFileCompletion:
|
|||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
|
qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
|
||||||
|
|
||||||
|
# foo should get completed from f
|
||||||
|
prompt.item_focus('next')
|
||||||
|
assert prompt._lineedit.text() == str(testdir / 'foo')
|
||||||
|
|
||||||
|
# Deleting /[foo]
|
||||||
|
for _ in range(3):
|
||||||
|
qtbot.keyPress(prompt._lineedit, Qt.Key_Backspace)
|
||||||
|
|
||||||
# We should now show / again, so tabbing twice gives us .. -> bar
|
# We should now show / again, so tabbing twice gives us .. -> bar
|
||||||
prompt.item_focus('next')
|
prompt.item_focus('next')
|
||||||
prompt.item_focus('next')
|
prompt.item_focus('next')
|
||||||
|
Loading…
Reference in New Issue
Block a user