|
38 | 38 | from novelwriter.core.item import NWItem |
39 | 39 | from novelwriter.dialogs.editlabel import GuiEditLabel |
40 | 40 | from novelwriter.enum import nwDocAction, nwDocInsert, nwItemClass, nwItemLayout, nwState |
41 | | -from novelwriter.gui.doceditor import GuiDocEditor, TextAutoReplace, _TagAction |
| 41 | +from novelwriter.gui.doceditor import CommandCompleter, GuiDocEditor, TextAutoReplace, _TagAction |
42 | 42 | from novelwriter.gui.dochighlight import TextBlockData |
43 | 43 | from novelwriter.text.counting import standardCounter |
44 | 44 | from novelwriter.types import ( |
@@ -1964,7 +1964,7 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd): |
1964 | 1964 | nwGUI.saveDocument() |
1965 | 1965 |
|
1966 | 1966 | docEditor.replaceText("") |
1967 | | - completer = docEditor._completer |
| 1967 | + completer: CommandCompleter = docEditor._completer |
1968 | 1968 |
|
1969 | 1969 | # Create Scene |
1970 | 1970 | nwGUI.docEditor.setFocus() |
@@ -2009,13 +2009,24 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd): |
2009 | 2009 |
|
2010 | 2010 | # Selecting "Jane" should insert it |
2011 | 2011 | completer.actions()[0].trigger() |
2012 | | - qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY) |
2013 | 2012 | assert docEditor.getText() == ( |
2014 | 2013 | "### Scene One\n\n" |
2015 | | - "@char: Jane\n" |
| 2014 | + "@char: Jane" |
2016 | 2015 | ) |
2017 | 2016 |
|
| 2017 | + # Adding a comma should reopen it |
| 2018 | + qtbot.keyClick(docEditor, ",", delay=KEY_DELAY) |
| 2019 | + qtbot.keyClick(docEditor, " ", delay=KEY_DELAY) |
| 2020 | + assert [a.text() for a in completer.actions()] == ["Jane", "John"] |
| 2021 | + |
| 2022 | + # Pressing return without selecting anything should just close it |
| 2023 | + qtbot.keyClick(completer, Qt.Key.Key_Return, delay=KEY_DELAY) |
| 2024 | + assert [a.text() for a in completer.actions()] == [] |
| 2025 | + qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY) |
| 2026 | + qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY) |
| 2027 | + |
2018 | 2028 | # Start a new line with a nonsense keyword, which should be handled |
| 2029 | + qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY) |
2019 | 2030 | for c in "@: ": |
2020 | 2031 | qtbot.keyClick(docEditor, c, delay=KEY_DELAY) |
2021 | 2032 | qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY) |
@@ -2074,19 +2085,19 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd): |
2074 | 2085 | "%Story.Resolution: \n" |
2075 | 2086 | ) |
2076 | 2087 |
|
2077 | | - # Auto-complete note comment |
| 2088 | + # Auto-complete note comment, but select with Tab |
2078 | 2089 | SHARED.project.index._itemIndex._cache.note.add("Consistency") |
2079 | 2090 | qtbot.keyClick(docEditor, "%", delay=KEY_DELAY) |
2080 | 2091 | assert len(completer.actions()) == 4 |
2081 | 2092 | qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY) |
2082 | 2093 | qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY) |
2083 | 2094 | qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY) |
2084 | 2095 | qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY) |
2085 | | - qtbot.keyClick(completer, Qt.Key.Key_Return, delay=KEY_DELAY) |
| 2096 | + qtbot.keyClick(completer, Qt.Key.Key_Tab, delay=KEY_DELAY) |
2086 | 2097 | qtbot.keyClick(completer, ".", delay=KEY_DELAY) |
2087 | 2098 | assert len(completer.actions()) == 1 |
2088 | 2099 | qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY) |
2089 | | - qtbot.keyClick(completer, Qt.Key.Key_Return, delay=KEY_DELAY) |
| 2100 | + qtbot.keyClick(completer, Qt.Key.Key_Tab, delay=KEY_DELAY) |
2090 | 2101 | qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY) |
2091 | 2102 | assert docEditor.getText() == ( |
2092 | 2103 | "### Scene One\n\n" |
|
0 commit comments