diff --git a/.vscode/settings.json b/.vscode/settings.json index ea7c19e3..a9a2810b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,10 @@ { - "python.pythonPath": ".venv/bin/python", + "python.pythonPath": ".venv/bin/python3.8", "python.testing.pytestArgs": [ "tests" ], "python.testing.unittestEnabled": false, "python.testing.nosetestsEnabled": false, - "python.testing.pytestEnabled": true + "python.testing.pytestEnabled": true, + "python.formatting.provider": "black" } \ No newline at end of file diff --git a/src/mycartable/classeur/sections/equation.py b/src/mycartable/classeur/sections/equation.py index 0683b166..bc98afa1 100644 --- a/src/mycartable/classeur/sections/equation.py +++ b/src/mycartable/classeur/sections/equation.py @@ -47,6 +47,8 @@ def update(self, curseur, event): @pyqtSlot(int, result=bool) def isEquationFocusable(self, curseur: int) -> bool: + if not any((self.content, curseur)): + return True return TextEquation( str(self.content), curseur, {"key": None, "text": None, "modifiers": None} ).is_focusable @@ -123,7 +125,7 @@ def __init__(self, lines: str, curseur: int, event): def __call__(self): if not self.lines_string: - if self.text and self.key != Qt.Key_Return: + if self.text and self.key != Qt.Key_Return and self.key != Qt.Key_Backspace: return f" \n{self.text}\n ", 3 else: return "", 0 diff --git a/src/mycartable/classeur/sections/operations/api.py b/src/mycartable/classeur/sections/operations/api.py index 7e097cfa..7d9aebcc 100644 --- a/src/mycartable/classeur/sections/operations/api.py +++ b/src/mycartable/classeur/sections/operations/api.py @@ -137,7 +137,10 @@ def convert_addition(numbers): signe = "+" if num_index else "" # pas de signe pour la premiere ligne res.append( [signe] - + num.to_string_list_addition(n_col - 1, apres_virgule=n_apres_virgule,) + + num.to_string_list_addition( + n_col - 1, + apres_virgule=n_apres_virgule, + ) ) # n_col-1 car signe prend une colonne num_index += 1 return n_row, n_col, virgule, list(itertools.chain.from_iterable(res)) diff --git a/src/qml/annotations/AnnotationDessin.qml b/src/qml/annotations/AnnotationDessin.qml index 8a5131b2..6b5c5ede 100644 --- a/src/qml/annotations/AnnotationDessin.qml +++ b/src/qml/annotations/AnnotationDessin.qml @@ -17,7 +17,7 @@ Canvas { property color fillStyle: annot.bgColor property real lineWidth: annot.pointSize property string tool: annot.tool - property int index + property int modelIndex: index // à priori pas utilisé ici mais on garde pour l'interface function checkPointIsNotDraw(mx, my) { var ctx = canvas.getContext("2d"); diff --git a/src/qml/annotations/AnnotationText.qml b/src/qml/annotations/AnnotationText.qml index bc0af6bc..9f8d064f 100644 --- a/src/qml/annotations/AnnotationText.qml +++ b/src/qml/annotations/AnnotationText.qml @@ -12,7 +12,7 @@ TextArea { property int moveStep: 5 property int fontSizeFactor: annot && annot.pointSize ? annot.pointSize : 0 property bool key_accepted: false // true pour le chargement initial - property int index + property int modelIndex:index function move(key) { if (key == Qt.Key_Left) @@ -39,7 +39,7 @@ TextArea { onTextChanged: { // on ne sauvegarde pas (pas de creation de command) si c un undo/redo/initial load if (key_accepted) - annot.set(index, { + annot.set(modelIndex, { "text": text }, "frappe"); @@ -107,6 +107,7 @@ TextArea { function onTextChanged() { if (text != annot.text) text = annot.text; + // annot.set(modelIndex, {"text":text}, "frappe"); } diff --git a/src/qml/annotations/BaseAnnotation.qml b/src/qml/annotations/BaseAnnotation.qml index 29c859f0..f7a7f549 100644 --- a/src/qml/annotations/BaseAnnotation.qml +++ b/src/qml/annotations/BaseAnnotation.qml @@ -36,7 +36,6 @@ Loader { root.setSource("qrc:/qml/annotations/" + annot.classtype + ".qml", { "referent": referent, "annot": annot, - "index": index }); } states: [ diff --git a/tests/python/classeur/test_equation.py b/tests/python/classeur/test_equation.py index 5809ad60..697fc744 100644 --- a/tests/python/classeur/test_equation.py +++ b/tests/python/classeur/test_equation.py @@ -51,6 +51,12 @@ def test_isequationfocusable(self, fk): assert not e.isEquationFocusable(0) assert e.isEquationFocusable(4) + def test_isequationfocusable_bug_131(self, fk): + eq = fk.f_equationSection(content="") + e = EquationSection.get(eq.id, parent=None, undoStack=QUndoStack()) + e.content="" + assert e.isEquationFocusable(0) + UN = """ ||1¤............¤12...1234....|| @@ -1228,3 +1234,9 @@ def test_sub(self): a = Fragment(5, 10, "\u2000\u2000bla\u2000", 0) a.sub(2, "X") assert a.value == "\u2000\u2000Xla\u2000" + + +def test_bug_131_backspace_sur_empty(eq): + a = eq("", 0, {"key": Qt.Key_Backspace ,"text": b'\x08'.decode(), "modifiers": None}) + a.lines_string="" + assert a()[0].encode() == b'' \ No newline at end of file diff --git a/tests/python/lexique/test_lexique.py b/tests/python/lexique/test_lexique.py index f5829274..184d5e78 100644 --- a/tests/python/lexique/test_lexique.py +++ b/tests/python/lexique/test_lexique.py @@ -232,7 +232,7 @@ def test_updateActivesLocales(qtbot): Test Quizz """ - +@pytest.mark.freeze_time('2017-03-03') class TestQuizz: provider = { diff --git a/tests/qml/tst_AnnotationText.qml b/tests/qml/tst_AnnotationText.qml index cc51a8d7..7b08bb17 100644 --- a/tests/qml/tst_AnnotationText.qml +++ b/tests/qml/tst_AnnotationText.qml @@ -40,9 +40,9 @@ FocusScope { annotobj = ref.model.data(ref.model.index(0, 0), th.getRole("AnnotationRole")); //258:AnnotationRole params = { "annot": annotobj, - "referent": item + "referent": item, + "modelIndex":0 }; - annotobj.index = 0; } function test_initY() { @@ -83,7 +83,8 @@ FocusScope { let aannoott2 = th.getBridgeInstance(ref, "AnnotationText", annot2.id); var tested2 = createObj(testedNom, { "annot": aannoott2, - "referent": item + "referent": item, + "modelIndex": 1 }, item); compare(tested2.fontSizeFactor, 3); compare(tested2.font.pixelSize, 66); // 200/3 diff --git a/tests/qml/tst_EquationSection.qml b/tests/qml/tst_EquationSection.qml index 073587cd..34fe8a84 100644 --- a/tests/qml/tst_EquationSection.qml +++ b/tests/qml/tst_EquationSection.qml @@ -71,6 +71,12 @@ Item { compare(tested.text, "1 \n__ + 1a\n15 "); } + function test_bug_131() { + eqObj.content = "" + mouseClick(tested) + keyClick(Qt.Key_Backspace) + } + name: "EquationSection" testedNom: "qrc:/qml/sections/EquationSection.qml" params: { diff --git a/tests/qml/tst_ImageSection.qml b/tests/qml/tst_ImageSection.qml index 167fca43..1a2184b4 100644 --- a/tests/qml/tst_ImageSection.qml +++ b/tests/qml/tst_ImageSection.qml @@ -280,6 +280,31 @@ Item { verify(!stack.canRedo); } + function test_bug_130() { + mouseClick(tested, 50, 50) + keySequence('a') + tryCompare(tested.annotations.itemAt(0).item,"text", "a") // on sépare pour avoir un poil de temps entre chaque clique + mouseClick(tested, 200, 200) + keySequence('e') + tryCompare(tested.annotations.itemAt(1).item,"text", "e") + mouseClick(tested, 400, 400) + keySequence('i') + tryCompare(tested.annotations.itemAt(2).item,"text", "i") + compare(tested.annotations.itemAt(0).item.modelIndex, 0) + compare(tested.annotations.itemAt(1).item.modelIndex, 1) + compare(tested.annotations.itemAt(2).item.modelIndex, 2) + mouseClick(tested, 51, 51, Qt.MiddleButton) + // verifie que l'index se met à jour + tryCompare(tested.annotations.itemAt(0).item,"text", "e") + tryCompare(tested.annotations.itemAt(1).item,"text", "i") + compare(tested.annotations.itemAt(0).item.modelIndex, 0) + compare(tested.annotations.itemAt(1).item.modelIndex, 1) + mouseMove(tested, 200, 200) + keySequence('m,n,o,p') + tryCompare(tested.annotations.itemAt(0).item,"text", "emnop") + compare(tested.annotations.itemAt(1).item.text, "i") + } + name: "ImageSection" testedNom: "qrc:/qml/sections/ImageSection.qml" params: {