Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/tst_omawrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,40 @@ private slots:
QCOMPARE(editor->property("font").value<QFont>().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<QObject> window(component.create());
QVERIFY2(window, qPrintable(component.errorString()));

QObject *editor = window->findChild<QObject *>(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());
Expand Down