diff --git a/src/Main.qml b/src/Main.qml index cdcbc3e..b830db0 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -26,9 +26,12 @@ ApplicationWindow { // the app at the sizes it was designed around. readonly property real textScale: backend.textScale readonly property int editorFontPixelSize: scaledSize(20) + // Never wider than the Flickable's viewport, whatever the floor asks for: + // a tiling compositor can resize the window below its minimum width. readonly property int editorWidth: Math.min( Math.round(writerFontMetrics.averageCharacterWidth * 65), - Math.max(360, width - Math.round(writerFontMetrics.averageCharacterWidth * 20))) + Math.max(360, width - Math.round(writerFontMetrics.averageCharacterWidth * 20)), + Math.max(0, width - 48)) property bool closeConfirmed: false property bool searchOpen: false property bool searchUpdating: false diff --git a/tests/tst_omawrite.cpp b/tests/tst_omawrite.cpp index 5c3306a..c14a1bd 100644 --- a/tests/tst_omawrite.cpp +++ b/tests/tst_omawrite.cpp @@ -218,6 +218,40 @@ private slots: QCOMPARE(editor->property("font").value().pixelSize(), 15); } + void keepsTextColumnInsideNarrowWindows() { + const QString mainQmlPath = QFINDTESTDATA("../src/Main.qml"); + QVERIFY(!mainQmlPath.isEmpty()); + + Backend backend; + QQmlEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("backend"), &backend); + QQmlComponent component(&engine, QUrl::fromLocalFile(mainQmlPath)); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer window(component.create()); + QVERIFY2(window, qPrintable(component.errorString())); + + QObject *editor = window->findChild(QStringLiteral("sourceEditor")); + QVERIFY(editor); + QObject *viewport = editor->parent(); + QVERIFY(viewport); + + // A resize reaches the window through its platform window, so the + // bindings only see the new width once the events are delivered. + const int minimumWidth = window->property("minimumWidth").toInt(); + window->setProperty("width", minimumWidth); + QCoreApplication::processEvents(); + QCOMPARE(window->property("width").toInt(), minimumWidth); + QVERIFY(editor->property("x").toInt() > 0); + + // A tiling compositor resizes below the minimum the window asks for. + window->setProperty("width", 394); + QCoreApplication::processEvents(); + QCOMPARE(window->property("width").toInt(), 394); + QVERIFY(editor->property("width").toInt() + <= viewport->property("width").toInt()); + QVERIFY(editor->property("x").toInt() >= 0); + } + void remembersLastSaveDirectory() { QTemporaryDir saveDirectory; QVERIFY(saveDirectory.isValid());