From d2ee2872ee6263688905a946362b9a16f7906d2c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 12:14:07 +0000 Subject: [PATCH 1/4] Optimize the views for phones On narrow screens (up to 600px), the lists leave out the columns which say little there (class "wideonly"): the author and version in the history of a page (the page of a version has them), the size of pages and files, and how to refer to an uploaded file. The list of all pages shows each page in two lines: the name, then the date and the icons, which don't fit next to it. The title bar and the toolbar wrap as a whole: the icons of a page stay together, and the search box takes the space which the icons leave. On touch screens, the icons of the bars and the lists are larger and have room around them to tap them (about 35px), and form fields have text of at least 16px, as iOS zooms into smaller text when a field gets the focus. Table cells break long words only where they don't fit (overflow-wrap: anywhere instead of word-break: break-all), so page names are no longer broken in the middle of words. Wide screens look as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AFJFMPuuJS5KWXNTediQpN --- README.md | 1 + functions.php | 10 +- index.css | 151 ++++++++++++++++++++++++++- src/Lists.php | 6 +- src/templates/all-pages.php | 7 +- src/templates/history.php | 7 +- src/templates/page.php | 7 +- src/templates/table-head.php | 5 +- src/templates/upload-list.php | 5 +- tests/Browser/mobile.spec.js | 115 ++++++++++++++++++++ tests/Integration/GitHistoryTest.php | 4 +- tests/Integration/ListViewsTest.php | 16 +++ tests/Integration/PageFrameTest.php | 5 +- tests/README.md | 2 +- 14 files changed, 316 insertions(+), 25 deletions(-) create mode 100644 tests/Browser/mobile.spec.js diff --git a/README.md b/README.md index 5f02aa1..a67a8bf 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ W2 wiki is a web-based, wiki-like notepad that you can host yourself. - Keyboard shortcuts (`?` shows the list): `/` search, `e` edit, `n` new page, `g` `h` home page, `g` `a` all pages, `h` history (with git); in the editor Ctrl+S or Ctrl+Enter save, Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+Alt+P preview, Alt+F10 formatting toolbar, Tab indents (Cmd and Option on a Mac). They only use the links of the page, and are left alone while typing; the pages work without them (and without JavaScript) - Localization support (en/de/ja/oc translations included) - Improved icon-based interface + - Phones: the lists leave out the columns which say little there (the author and version in the history of a page, the size of pages and files, how to refer to a file), the list of all pages shows the name above the date and the icons, the title bar and the toolbar wrap as a whole, and on touch screens the icons are larger, with room to tap them; form fields have text of at least 16px, as iOS zooms into smaller text - Optional sidebar fed by a special page (shown when viewing pages, in the page list and in search results, but not when editing) - Merged All/Recent list of all pages - Links: diff --git a/functions.php b/functions.php index d8a3e79..81ecf23 100644 --- a/functions.php +++ b/functions.php @@ -939,16 +939,18 @@ function humanFilesize($bytes, $decimals = 2) { * * @param string $action the action which shows the table (the headings are links to it) * @param string $sortBy the column which the table is sorted by - * @param array $columns the label of each column, and what to sort by to - * sort by it (or null for a column which can't be sorted by) + * @param array $columns the label of each column, what to sort by + * to sort by it (or null for a column which can't be sorted by), and the class of its cell + * (optional, e.g. "wideonly" for a column which narrow screens don't show) * return W2\Html */ function sortableHeadings($action, $sortBy, $columns) { $headings = array(); - foreach ($columns as list($label, $key)) + foreach ($columns as $column) { - $headings[] = array('label' => $label, 'current' => ($key !== null && $key === $sortBy), + list($label, $key) = $column; + $headings[] = array('label' => $label, 'current' => ($key !== null && $key === $sortBy), 'class' => $column[2] ?? '', 'href' => ($key === null || $key === $sortBy) ? null : SELF . "?action=" . $action . "&sortBy=" . $key); } return templates()->render('table-head', array('columns' => $headings)); diff --git a/index.css b/index.css index d5746f4..60a270b 100644 --- a/index.css +++ b/index.css @@ -175,7 +175,8 @@ table { } td, th { padding: .1em 1em .1em .1em; - word-break: break-all; + /* (long words are broken only where they don't fit, so that a table can be narrower than the window) */ + overflow-wrap: anywhere; } thead { border-bottom: 1px solid var(--table-rule); @@ -547,6 +548,8 @@ input.search:focus { input.pagename { width: 20em; + max-width: 100%; + box-sizing: border-box; } input[type="button"], @@ -1116,3 +1119,149 @@ body.editor form#edit > .formatbar + .editorbox { animation: none; } } + +/* + * Small screens and touch screens. Narrow screens (phones) don't show the columns of the lists which say little + * there (.wideonly: the author and version in the history of a page, which the page of a version has, the size of + * pages and files, how to refer to a file), and the title bar and the toolbar wrap as a whole: the icons of a page + * stay together, and the search box takes the space which the icons leave. On touch screens, the icons are larger and + * have room around them for a finger; the text of form fields has at least 16px, as iOS zooms into smaller text when + * the field gets the focus. + */ + @media (max-width: 600px) { + .wideonly { + display: none; + } + .main { + padding-right: .75em; + } + img { + max-width: 100%; + } + .login { + margin: 1em; + } + .titlebar { + display: flex; + flex-wrap: wrap; + align-items: center; + column-gap: .5em; + } + .titlebar span.title { + overflow-wrap: anywhere; + } + .titledate { + margin: 0; + } + .titlebar .pageactions { + margin-left: auto; + white-space: nowrap; + } + .toolbar { + display: flex; + flex-wrap: wrap; + align-items: center; + } + .toolbar .searchform { + display: block; + flex: 1 1 5em; + min-width: 5em; + margin-right: .5em; + } + input.search, input.search:focus { + width: 100%; + box-sizing: border-box; + } + .toolbar .themeswitch { + float: none; + } + .pageActions { + padding-left: 0; + padding-right: 0; + white-space: nowrap; + } + /* (headings are broken between words, unless a word is wider than the column) */ + th { + overflow-wrap: break-word; + } + /* (the list of all pages: each row in two lines, the name above the date and the icons, which don't fit next to it) */ + table.pagelist, table.pagelist thead, table.pagelist tbody { + display: block; + max-width: none; + } + table.pagelist tr { + display: grid; + grid-template-columns: 1fr auto; + grid-template-areas: "name name" "modified actions"; + align-items: center; + column-gap: .5em; + padding: .2em 0 0 .2em; + } + table.pagelist thead tr { + grid-template-areas: "name modified"; + } + table.pagelist thead th:last-child { + display: none; + } + table.pagelist td, table.pagelist th { + padding: 0; + } + table.pagelist .pagename { + grid-area: name; + } + table.pagelist .modified { + grid-area: modified; + font-size: .9em; + } + table.pagelist .pageActions { + grid-area: actions; + white-space: nowrap; + } + table.history td:first-child, td.modified { + overflow-wrap: normal; + } + /* (the date of the lists can wrap before the time) */ + td.modified nobr { + white-space: normal; + } + } + @media (pointer: coarse) { + .titlebar .pageactions a, .toolbar > a, .pageActions a { + display: inline-block; + padding: 6px; + margin: 0; + line-height: 0; + } + .toolbar > a:not(:has(svg)) { + line-height: normal; + } + .toolbar { + padding-left: calc(1em - 6px); + } + .titlebar svg.icon, .toolbar svg.icon, .pageActions svg.icon { + width: 1.5rem; + height: 1.5rem; + } + .themeswitch button { + padding: 6px; + } + .themeswitch svg.icon { + width: 1.5rem; + height: 1.5rem; + } + input[type="text"], input[type="password"], input[type="number"], input.search, textarea, select { + font-size: 16px; + } + input[type="button"], input[type="submit"] { + padding: .7em 1.2em; + margin-bottom: .3em; + } + .sidebar li, .linkshere li { + line-height: 2em; + } + } + @media (hover: none) { + a > svg.icon:hover { + outline: none; + } + } diff --git a/src/Lists.php b/src/Lists.php index 4c89767..bbcdf98 100644 --- a/src/Lists.php +++ b/src/Lists.php @@ -46,7 +46,7 @@ public function allPages(string $sortBy): Html return templates()->render('all-pages', array( 'total' => count($pageNames), 'rows' => $rows, 'head' => sortableHeadings('all', $sortBy, array( - array(translate('Name'), 'name'), array(translate('Modified'), 'recent'), array(translate('Size'), 'size'), array(translate('Action'), null))) + array(translate('Name'), 'name'), array(translate('Modified'), 'recent'), array(translate('Size'), 'size', 'wideonly'), array(translate('Action'), null))) )); } @@ -81,8 +81,8 @@ public function uploads(string $sortBy, string $prevPage): Html } } - $columns = array(array(translate('Name'), 'name'), array(translate('Usage'), null), - array(translate('Modified'), 'recent'), array(translate('Size'), 'size'), array(translate('Action'), null)); + $columns = array(array(translate('Name'), 'name'), array(translate('Usage'), null, 'wideonly'), + array(translate('Modified'), 'recent'), array(translate('Size'), 'size', 'wideonly'), array(translate('Action'), null)); if (SHOW_PAGES_WHERE_FILE_USED) { $columns[] = array(translate('Used on page'), null); diff --git a/src/templates/all-pages.php b/src/templates/all-pages.php index 1155ddf..5c3c192 100644 --- a/src/templates/all-pages.php +++ b/src/templates/all-pages.php @@ -4,12 +4,13 @@ * * The list of all pages (inside the main part of page). * - * Values: total (number), head (Html: the heading cells, see table-head), + * Values: total (number), head (Html: the heading cells, see table-head; narrow screens don't show the size, see + * "wideonly" in index.css, and show each row in two lines: the name, then the date and the icons), * rows (list of: href, name, modified (text), size (text), actions (Html: see page-actions)) */ ?> -

: total ?>

head ?> +

: total ?>

head ?>rows as $row): ?> - +
diff --git a/src/templates/history.php b/src/templates/history.php index 418e817..507ca71 100644 --- a/src/templates/history.php +++ b/src/templates/history.php @@ -9,6 +9,7 @@ * rows (list of: date (text), subject (text: the first line of the message), author (text), shortHash (text), * deleted (bool: the page was deleted in this version, which has no links), versionHref, changesHref (what * this version changed), compareHref (this version compared with the current text): text) + * Narrow screens don't show the author and the version ("wideonly", see index.css): the page of a version has them. */ ?> total === 0): ?> @@ -17,12 +18,12 @@

first, $this->last, $this->total) ?> newerHref !== null): ?> olderHref !== null): ?>

- +
rows as $row): ?> - + - +
()
()
diff --git a/src/templates/page.php b/src/templates/page.php index e6466d2..809b5e2 100644 --- a/src/templates/page.php +++ b/src/templates/page.php @@ -4,7 +4,8 @@ * * The page of the wiki (inside layout): title bar, toolbar, sidebar, and the main part with the note. * - * Values: title (text), modified (text, or '' for pages without a date), pageActions (Html or null), + * Values: title (text), modified (text, or '' for pages without a date), pageActions (Html or null: the icons in the + * title bar, which are kept together when the bar wraps on narrow screens), * toolbar (list of items: href, icon (Html, see iconSvg(), or null for a link with a text only), label, * shortcut (text: the keys of the keyboard shortcut which follows the link, like "g h"; or null)), * drawer (Html or null), themeSwitch (Html: the buttons to choose the color scheme), sidebar (Html or null), @@ -14,7 +15,7 @@ * wiki.js), so that a page only has the shortcuts of what it shows. */ ?> -
title ?>modified !== ''): ?>modified ?>pageActions ?> +
title ?>modified !== ''): ?>modified ?>pageActions !== null): ?>pageActions ?>
@@ -28,7 +29,7 @@ -
+
diff --git a/src/templates/table-head.php b/src/templates/table-head.php index f9dc377..79bec4a 100644 --- a/src/templates/table-head.php +++ b/src/templates/table-head.php @@ -5,9 +5,10 @@ * The headings of a table which can be sorted by some of its columns (one cell each). * * Values: columns (list of: label, href (the address to sort by this column, or null), current (bool: the table is - * sorted by this column, which is shown without a link)) + * sorted by this column, which is shown without a link), class (text: the class of the cell, e.g. "wideonly" + * for a column which narrow screens don't show, see index.css; or '')) */ ?> columns as $column): ?> - +> diff --git a/src/templates/upload-list.php b/src/templates/upload-list.php index 470d77c..5e7f0f4 100644 --- a/src/templates/upload-list.php +++ b/src/templates/upload-list.php @@ -4,7 +4,8 @@ * * The list of the uploaded files (inside the main part of page). * - * Values: total (number), head (Html: the heading cells, see table-head), showUsage (bool: where the files are used + * Values: total (number), head (Html: the heading cells, see table-head; narrow screens don't show how to refer to + * a file and its size, see "wideonly" in index.css), showUsage (bool: where the files are used * is shown), rows (list of: thumbnail (the address of the image, or null for files which are no images), name, * markdown (text: how to refer to the file in a page), modified (text), size (text), renameHref, deleteHref, * pages (list of: href, name)) @@ -12,6 +13,6 @@ ?>

: total ?>

head ?>rows as $row): ?> -showUsage): ?> +showUsage): ?>
diff --git a/tests/Browser/mobile.spec.js b/tests/Browser/mobile.spec.js new file mode 100644 index 0000000..f95595c --- /dev/null +++ b/tests/Browser/mobile.spec.js @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: MIT + +// Phones (in the wiki with git, see gitBase(), which has the history of pages): no view is wider than the screen, the lists +// leave out the columns which say little there (author and version of the history, the size of pages and files, how to +// refer to a file), the list of all pages shows the name above the date and the icons, the icons are large enough to tap, +// and the text of form fields is large enough that iOS doesn't zoom into it. +const { test, expect } = require('@playwright/test'); +const { savePage, upload, png, gitBase } = require('./helpers'); + +const name = 'Phone ' + Date.now(); +const views = { + page: () => '/index.php/' + encodeURIComponent(name), + all: () => '/index.php?action=all', + history: () => '/index.php?action=history&page=' + encodeURIComponent(name), + editor: () => '/index.php?action=edit&page=' + encodeURIComponent(name), + new: () => '/index.php?action=new', + upload: () => '/index.php?action=upload&page=Home', + search: () => '/index.php?action=search&q=Phone', + rename: () => '/index.php?action=rename&page=' + encodeURIComponent(name), +}; + +test.describe('narrow screens', () => { + test.use({ baseURL: gitBase(), hasTouch: true, isMobile: true, viewport: { width: 390, height: 800 } }); + + test.beforeAll(async ({ request }) => { + await savePage(request, name + ' with a long name, so that it has to wrap on a phone', 'text', gitBase()); + await savePage(request, name, '# A page\n\n| Column one | Column two | Column three |\n|---|---|---|\n| averyveryverylongwordwithoutspaces | b | c |\n\n```\na long line of code which is much wider than the screen of a phone, of course\n```\n', gitBase()); + expect((await upload(request, 'phone-photo-with-a-long-name.png', png(40, 20), 'image/png', gitBase())).status()).toBe(303); + }); + + for (const width of [320, 390]) { + test(`no view is wider than ${width} pixels`, async ({ page }) => { + await page.setViewportSize({ width, height: 800 }); + for (const [view, url] of Object.entries(views)) { + await page.goto(url()); + const scrollWidth = await page.evaluate(() => document.documentElement.scrollWidth); + expect(scrollWidth, view).toBeLessThanOrEqual(width); + } + }); + } + + test('the history leaves out the author and the version', async ({ page }) => { + await page.goto(views.history()); + const row = page.locator('table.history tbody tr').first(); + await expect(row.locator('td').first()).toBeVisible(); + await expect(page.locator('table.history th', { hasText: 'Author' })).toBeHidden(); + await expect(page.locator('table.history th', { hasText: 'Version' })).toBeHidden(); + await expect(row.locator('code')).toBeHidden(); + // (on wide screens, they are there) + await page.setViewportSize({ width: 1024, height: 800 }); + await expect(page.locator('table.history th', { hasText: 'Author' })).toBeVisible(); + await expect(row.locator('code')).toBeVisible(); + }); + + test('the list of all pages shows the name above the date and the icons, without the size', async ({ page }) => { + await page.goto(views.all()); + await expect(page.locator('table.pagelist th', { hasText: 'Size' })).toBeHidden(); + const row = page.locator('table.pagelist tbody tr', { has: page.locator(`a:text-is("${name}")`) }); + const nameBox = await row.locator('td.pagename').boundingBox(); + const dateBox = await row.locator('td.modified').boundingBox(); + const iconsBox = await row.locator('td.pageActions').boundingBox(); + expect(dateBox.y).toBeGreaterThanOrEqual(nameBox.y + nameBox.height - 1); + expect(iconsBox.y).toBeGreaterThanOrEqual(nameBox.y + nameBox.height - 1); + expect(iconsBox.x).toBeGreaterThan(dateBox.x + dateBox.width); + // (the five icons in one line) + const tops = await row.locator('td.pageActions a').evaluateAll((links) => links.map((link) => link.getBoundingClientRect().top)); + expect(tops.length).toBe(5); + expect(new Set(tops).size).toBe(1); + + await page.goto(views.upload()); + await expect(page.locator('th', { hasText: 'Usage' })).toBeHidden(); + await expect(page.locator('th', { hasText: 'Size' })).toBeHidden(); + await expect(page.locator('th', { hasText: 'Modified' })).toBeVisible(); + }); + + test('icons are large enough to tap, and form fields are not zoomed into', async ({ page }) => { + for (const [url, selector] of [[views.page(), '.titlebar .pageactions a'], [views.page(), '.toolbar > a'], [views.all(), 'td.pageActions a'], + [views.upload(), 'td.pageActions a'], [views.page(), '.themeswitch button']]) { + await page.goto(url); + const sizes = await page.locator(selector).evaluateAll((elements) => elements.map((element) => { + const box = element.getBoundingClientRect(); + return [box.width, box.height]; + })); + expect(sizes.length, selector).toBeGreaterThan(0); + for (const [width, height] of sizes) { + expect(Math.min(width, height), selector).toBeGreaterThanOrEqual(34); + } + } + // (the page's icons stay together, after the title) + await page.goto(views.page()); + const tops = await page.locator('.titlebar .pageactions a').evaluateAll((links) => links.map((link) => link.getBoundingClientRect().top)); + expect(new Set(tops).size).toBe(1); + + for (const [url, selector] of [[views.page(), '#search'], [views.editor(), '#text'], [views.editor(), '#gitmsg'], [views.new(), '#title'], [views.rename(), '#newName']]) { + await page.goto(url); + const fontSize = await page.locator(selector).evaluate((element) => parseFloat(getComputedStyle(element).fontSize)); + expect(fontSize, selector).toBeGreaterThanOrEqual(16); + } + }); +}); + +test.describe('wide screens with a mouse', () => { + test.use({ baseURL: gitBase(), viewport: { width: 1280, height: 800 } }); + + test('the lists have all their columns, and the icons their size', async ({ page }) => { + await page.goto(views.all()); + await expect(page.locator('table.pagelist th', { hasText: 'Size' })).toBeVisible(); + await expect(page.locator('table.pagelist th', { hasText: 'Action' })).toBeVisible(); + expect(await page.locator('table.pagelist tbody tr').first().evaluate((row) => getComputedStyle(row).display)).toBe('table-row'); + const icon = await page.locator('.toolbar svg.icon').first().boundingBox(); + expect(icon.width).toBeLessThan(22); + await page.goto(views.upload()); + await expect(page.locator('th', { hasText: 'Usage' })).toBeVisible(); + }); +}); diff --git a/tests/Integration/GitHistoryTest.php b/tests/Integration/GitHistoryTest.php index b9c4aec..18bb929 100644 --- a/tests/Integration/GitHistoryTest.php +++ b/tests/Integration/GitHistoryTest.php @@ -24,7 +24,7 @@ private function hashes(string $file = ''): array /** The rows of the list of versions: date, subject, short hash, and the links */ private function rows(string $body): array { - preg_match_all('#(?:)?([^<]*)(?:)?(.*?)[^<]*([0-9a-f]+)#', $body, $matches, PREG_SET_ORDER); + preg_match_all('#(?:)?([^<]*)(?:)?(.*?)[^<]*([0-9a-f]+)#', $body, $matches, PREG_SET_ORDER); return array_map(fn($m) => ['href' => html_entity_decode($m[1]), 'subject' => html_entity_decode(strip_tags($m[3]), ENT_QUOTES), 'hash' => $m[4]], $matches); } @@ -273,7 +273,7 @@ public function testMessagesAndAuthorsAreEscaped(): void $body = $this->view('history', 'Home')->body; $this->assertStringContainsString('Home: <script>alert(1)</script> & "quotes"', $body); $this->assertStringContainsString('<img src=x onerror=alert(2)>', $body); - $this->assertStringContainsString('Mallory & "Co', $body); + $this->assertStringContainsString('Mallory & "Co', $body); $this->assertNoActiveContent($body); $version = $this->view('version', 'Home', ['rev' => $this->hashes('Home.md')[1]])->body; $this->assertStringContainsString('<script>alert(1)</script>', $version); diff --git a/tests/Integration/ListViewsTest.php b/tests/Integration/ListViewsTest.php index eb5e78d..154d330 100644 --- a/tests/Integration/ListViewsTest.php +++ b/tests/Integration/ListViewsTest.php @@ -20,6 +20,22 @@ public function testAllPagesListsNamesWithActionIcons(): void $this->assertStringContainsString('sortBy=size', $body); } + public function testColumnsWhichNarrowScreensLeaveOut(): void + { + // (index.css hides .wideonly on narrow screens, and shows each row of the list of all pages in two lines) + $body = $this->http->get('/index.php', ['action' => 'all'])->body; + $this->assertStringContainsString('', $body); + $this->assertMatchesRegularExpression('##', $body); + $this->assertMatchesRegularExpression('##', $body, 'the other columns have no class'); + + $this->upload('a.gif', self::gif()); + $body = $this->http->get('/index.php', ['action' => 'upload'])->body; + $this->assertStringContainsString('', $body); + $this->assertMatchesRegularExpression('##', $body); + $this->assertMatchesRegularExpression('#
Size
Home[^<]+[^<]+#', $body); + $this->assertMatchesRegularExpression('#ModifiedUsageSize
!\[[^<]*\]\(/images/a.gif\)
[^<]+[^<]+upload('a.gif', self::gif()); diff --git a/tests/Integration/PageFrameTest.php b/tests/Integration/PageFrameTest.php index cf31435..66dc5b6 100644 --- a/tests/Integration/PageFrameTest.php +++ b/tests/Integration/PageFrameTest.php @@ -44,7 +44,7 @@ public function testToolbar(): void array_map(fn($item) => [$item[1], $item[2], $item[3]], $items) ); $this->assertStringNotContainsString('action=logout', $body, 'no way to log out without a password'); - $this->assertStringContainsString('
', $body); + $this->assertStringContainsString('', $body); $this->assertStringContainsString('', $body); } @@ -99,6 +99,9 @@ public function testPageActionsInTheTitleBarOnlyForPages(): void } $this->assertStringNotContainsString("action=$current&page=Home", $bar, "$current while doing $current"); } + // (in a group, which stays together when the bar wraps on narrow screens) + $this->assertMatchesRegularExpression('#^Home[^<]+(\s*]*>]*>.*?)+\s*\s*$#s', $this->titleBar('/index.php/Home')); + $this->assertStringNotContainsString('pageactions', $this->titleBar('/index.php?action=all')); $this->assertStringNotContainsString('titleBar('/index.php?action=all')); $this->assertStringNotContainsString('titleBar('/index.php?action=search&q=x')); } diff --git a/tests/README.md b/tests/README.md index bcf8e54..338e984 100644 --- a/tests/README.md +++ b/tests/README.md @@ -130,7 +130,7 @@ browser (Chromium): stored and reflected XSS payloads (the same texts as the PHP file names, and uploaded SVG files opened directly. Any `alert()` or event handler that runs fails a test. `canary.spec.js` checks that the helpers really notice scripts. The other specs check behaviour of pages that needs a browser: the keyboard shortcuts of every page (`shortcuts.spec.js`: each key, the keys which are left alone while typing, with modifiers, repeated or during an input method, the list which `?` shows, the history with git, and the pages without a script), the editor (`editor.spec.js`, `autosave.spec.js`, its keys in `editor-keys.spec.js`: saving, bold, italic, links and undoing them, the preview, indenting with Tab in `editor-indent.spec.js`, the formatting toolbar in `toolbar.spec.js`: every button, the menu of the headings, the dialog for tables with its limits, tables of tab- or comma-separated lines, undoing each change in one step, the draft and the preview, the focus and the keyboard, narrow screens, the dark scheme and the editor without a script, inserting text files in `editor-import.spec.js`, dropping files and images in `dragdrop.spec.js`: the position of the drop in the text (compared with where a click puts the cursor, also after scrolling and with `caretRangeFromPoint()` of older browsers), the cursor following the drag, several files in their order, drops next to the text (preview, toolbar, buttons) which the browser must not open, the hint over the page (shown, hidden, readable in both schemes), drags of text and links which are left alone (also a real drag of selected text), images of the wiki's uploads (from the upload page, and a real drag from the preview) and of other sites, `javascript:` and `data:` addresses which are ignored, undoing, the preview and the draft, and the upload page, the preview in `preview.spec.js`: updates while typing, the button and the remembered choice, the layout on wide and narrow screens, links, errors, and payloads which must not run in it) -the search box of the toolbar (`search.spec.js`) and uploading with the dialog and the crop frame, from the editor (`editor-upload.spec.js`) and the upload page (`upload-page.spec.js`), the history of a page with git (`history.spec.js`: from the page to the versions, the changes of a version and restoring it), highlighted code blocks (`code-highlighting.spec.js`: readable in both color schemes, without violating the content security policy), and the color schemes (`dark-mode.spec.js`: contrast of the text in every view, and light mode staying as it was; `theme-switch.spec.js`: the buttons of the toolbar, with and without a script, and that the icons are drawn from their files without violating the content security policy). +the search box of the toolbar (`search.spec.js`) and uploading with the dialog and the crop frame, from the editor (`editor-upload.spec.js`) and the upload page (`upload-page.spec.js`), the history of a page with git (`history.spec.js`: from the page to the versions, the changes of a version and restoring it), highlighted code blocks (`code-highlighting.spec.js`: readable in both color schemes, without violating the content security policy), and the color schemes (`dark-mode.spec.js`: contrast of the text in every view, and light mode staying as it was; `theme-switch.spec.js`: the buttons of the toolbar, with and without a script, and that the icons are drawn from their files without violating the content security policy), and phones (`mobile.spec.js`: no view wider than the screen at 320 and 390 pixels, the columns which the lists leave out there, the list of all pages in two lines per page, icons large enough to tap and form fields with text of at least 16px, and the wide screen staying as it was). ``` cd tests/Browser From b7cd0f5adadf92c5102c4af286994434d89e4c74 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 17:14:32 +0000 Subject: [PATCH 2/4] Phones: one line for the title bar, and room for the text while typing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The title bar of phones was two lines (title and date, then the icons of the page) above the toolbar: 113px of the screen. It is one line now, the title (cut off with "…" if it is too long) above the date in small text, and the icons next to them; the bars have less padding. Both bars take 75px. While the text of the editor has the focus on a phone (touch screen up to 600px wide, or less than 500px high, as with the on-screen keyboard), the title bar and the toolbar are hidden, which almost doubles the height of the text with the keyboard open (202px instead of 110px of 420px). The buttons of the formatting toolbar keep the focus in the text, and Save stays where it is when the bars come back. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AFJFMPuuJS5KWXNTediQpN --- README.md | 2 +- index.css | 44 +++++++++++++++++++----- tests/Browser/mobile.spec.js | 66 ++++++++++++++++++++++++++++++++---- tests/README.md | 2 +- 4 files changed, 97 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a67a8bf..234e862 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ W2 wiki is a web-based, wiki-like notepad that you can host yourself. - Keyboard shortcuts (`?` shows the list): `/` search, `e` edit, `n` new page, `g` `h` home page, `g` `a` all pages, `h` history (with git); in the editor Ctrl+S or Ctrl+Enter save, Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+Alt+P preview, Alt+F10 formatting toolbar, Tab indents (Cmd and Option on a Mac). They only use the links of the page, and are left alone while typing; the pages work without them (and without JavaScript) - Localization support (en/de/ja/oc translations included) - Improved icon-based interface - - Phones: the lists leave out the columns which say little there (the author and version in the history of a page, the size of pages and files, how to refer to a file), the list of all pages shows the name above the date and the icons, the title bar and the toolbar wrap as a whole, and on touch screens the icons are larger, with room to tap them; form fields have text of at least 16px, as iOS zooms into smaller text + - Phones: the lists leave out the columns which say little there (the author and version in the history of a page, the size of pages and files, how to refer to a file), the list of all pages shows the name above the date and the icons, the title bar is one line (the title above the date, the page's icons next to them), the title bar and the toolbar are hidden while the text of the editor is typed, and on touch screens the icons are larger, with room to tap them; form fields have text of at least 16px, as iOS zooms into smaller text - Optional sidebar fed by a special page (shown when viewing pages, in the page list and in search results, but not when editing) - Merged All/Recent list of all pages - Links: diff --git a/index.css b/index.css index 60a270b..a2dee2e 100644 --- a/index.css +++ b/index.css @@ -1123,10 +1123,11 @@ body.editor form#edit > .formatbar + .editorbox { /* * Small screens and touch screens. Narrow screens (phones) don't show the columns of the lists which say little * there (.wideonly: the author and version in the history of a page, which the page of a version has, the size of - * pages and files, how to refer to a file), and the title bar and the toolbar wrap as a whole: the icons of a page - * stay together, and the search box takes the space which the icons leave. On touch screens, the icons are larger and - * have room around them for a finger; the text of form fields has at least 16px, as iOS zooms into smaller text when - * the field gets the focus. + * pages and files, how to refer to a file). The title bar is one line, to leave the space to the page: the title (cut + * off with "…" if it is too long) above the date, and the icons of the page next to them; in the toolbar, the search box + * takes the space which the icons leave. On touch screens, the icons are larger and have room around them for a finger; + * the text of form fields has at least 16px, as iOS zooms into smaller text when the field gets the focus. While the + * text of the editor has the focus on a phone (with the on-screen keyboard), the title bar and the toolbar are hidden. */ @media (max-width: 600px) { .wideonly { @@ -1142,19 +1143,39 @@ body.editor form#edit > .formatbar + .editorbox { margin: 1em; } .titlebar { - display: flex; - flex-wrap: wrap; + display: grid; + grid-template-columns: minmax(0, 1fr) auto; + grid-template-areas: "title actions" "date actions"; align-items: center; column-gap: .5em; + padding-top: 2px; + padding-bottom: 2px; } .titlebar span.title { - overflow-wrap: anywhere; + grid-area: title; + align-self: end; + font-size: 1.15em; + line-height: 1.2; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + /* (without a date, the title is in the middle of the bar) */ + .titlebar:not(:has(.titledate)) span.title { + grid-row: 1 / span 2; + align-self: center; } .titledate { + grid-area: date; + align-self: start; margin: 0; + font-size: .8em; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } .titlebar .pageactions { - margin-left: auto; + grid-area: actions; white-space: nowrap; } .toolbar { @@ -1236,7 +1257,7 @@ body.editor form#edit > .formatbar + .editorbox { line-height: normal; } .toolbar { - padding-left: calc(1em - 6px); + padding: 0 4px 0 calc(1em - 6px); } .titlebar svg.icon, .toolbar svg.icon, .pageActions svg.icon { width: 1.5rem; @@ -1260,6 +1281,11 @@ body.editor form#edit > .formatbar + .editorbox { line-height: 2em; } } + @media (pointer: coarse) and (max-width: 600px), (pointer: coarse) and (max-height: 500px) { + body.editor:has(#text:focus) > .titlebar, body.editor:has(#text:focus) > .toolbar { + display: none; + } + } @media (hover: none) { a > svg.icon:hover { outline: none; diff --git a/tests/Browser/mobile.spec.js b/tests/Browser/mobile.spec.js index f95595c..08d0556 100644 --- a/tests/Browser/mobile.spec.js +++ b/tests/Browser/mobile.spec.js @@ -2,8 +2,9 @@ // Phones (in the wiki with git, see gitBase(), which has the history of pages): no view is wider than the screen, the lists // leave out the columns which say little there (author and version of the history, the size of pages and files, how to -// refer to a file), the list of all pages shows the name above the date and the icons, the icons are large enough to tap, -// and the text of form fields is large enough that iOS doesn't zoom into it. +// refer to a file), the list of all pages shows the name above the date and the icons, the title bar is one line, the +// icons are large enough to tap, the text of form fields is large enough that iOS doesn't zoom into it, and the bars +// make room for the text of the editor while it is typed. const { test, expect } = require('@playwright/test'); const { savePage, upload, png, gitBase } = require('./helpers'); @@ -86,10 +87,6 @@ test.describe('narrow screens', () => { expect(Math.min(width, height), selector).toBeGreaterThanOrEqual(34); } } - // (the page's icons stay together, after the title) - await page.goto(views.page()); - const tops = await page.locator('.titlebar .pageactions a').evaluateAll((links) => links.map((link) => link.getBoundingClientRect().top)); - expect(new Set(tops).size).toBe(1); for (const [url, selector] of [[views.page(), '#search'], [views.editor(), '#text'], [views.editor(), '#gitmsg'], [views.new(), '#title'], [views.rename(), '#newName']]) { await page.goto(url); @@ -97,6 +94,58 @@ test.describe('narrow screens', () => { expect(fontSize, selector).toBeGreaterThanOrEqual(16); } }); + + for (const width of [320, 390]) { + test(`the title bar is one line at ${width} pixels: the title above the date, the icons next to them`, async ({ page }) => { + await page.setViewportSize({ width, height: 800 }); + for (const view of ['page', 'history', 'editor', 'all']) { + await page.goto(views[view]()); + const bar = await page.locator('.titlebar').boundingBox(); + const title = await page.locator('.titlebar .title').boundingBox(); + expect(bar.height, view).toBeLessThanOrEqual(42); + expect(title.x + title.width, view).toBeLessThanOrEqual(width); + expect(await page.locator('.toolbar').evaluate((toolbar) => toolbar.getBoundingClientRect().bottom), view).toBeLessThanOrEqual(80); + const icons = page.locator('.titlebar .pageactions a'); + if (await icons.count() > 0) { + const boxes = await icons.evaluateAll((links) => links.map((link) => link.getBoundingClientRect()).map((box) => [box.top, box.right])); + expect(new Set(boxes.map(([top]) => top)).size, view).toBe(1); + expect(Math.max(...boxes.map(([, right]) => right)), view).toBeLessThanOrEqual(width); + expect(boxes[0][1], view).toBeGreaterThan(title.x + title.width); + } + } + // (a long title is cut off, the date below it is shown) + await page.goto('/index.php/' + encodeURIComponent(name + ' with a long name, so that it has to wrap on a phone')); + const title = page.locator('.titlebar .title'); + expect(await title.evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(true); + const titleBox = await title.boundingBox(); + const dateBox = await page.locator('.titlebar .titledate').boundingBox(); + expect(dateBox.y).toBeGreaterThanOrEqual(titleBox.y + titleBox.height - 1); + }); + } + + test('while the text of the editor is typed, the title bar and the toolbar make room for it', async ({ page }) => { + // (the space which the on-screen keyboard leaves) + await page.setViewportSize({ width: 390, height: 420 }); + await page.goto(views.editor()); + await expect(page.locator('.titlebar')).toBeVisible(); + const before = (await page.locator('#text').boundingBox()).height; + await page.locator('#text').tap(); + await expect(page.locator('.titlebar')).toBeHidden(); + await expect(page.locator('.toolbar')).toBeHidden(); + expect((await page.locator('#text').boundingBox()).height).toBeGreaterThan(before + 60); + // (the buttons of the formatting toolbar leave the focus in the text) + await page.locator('#formatbar button[data-format="bold"]').tap(); + await expect(page.locator('#text')).toBeFocused(); + await expect(page.locator('.titlebar')).toBeHidden(); + // (elsewhere, they are back; Save is where it was, and saves) + const save = await page.locator('#save').boundingBox(); + await page.locator('#gitmsg').tap(); + await expect(page.locator('.titlebar')).toBeVisible(); + expect((await page.locator('#save').boundingBox()).y).toBe(save.y); + await page.locator('#text').tap(); + await Promise.all([page.waitForURL(/\/index\.php\/Phone/), page.locator('#save').tap()]); + await expect(page.locator('.titlebar')).toBeVisible(); + }); }); test.describe('wide screens with a mouse', () => { @@ -111,5 +160,10 @@ test.describe('wide screens with a mouse', () => { expect(icon.width).toBeLessThan(22); await page.goto(views.upload()); await expect(page.locator('th', { hasText: 'Usage' })).toBeVisible(); + // (the bars stay while the text of the editor is typed) + await page.goto(views.editor()); + await page.locator('#text').click(); + await expect(page.locator('.titlebar')).toBeVisible(); + await expect(page.locator('.toolbar')).toBeVisible(); }); }); diff --git a/tests/README.md b/tests/README.md index 338e984..c6aac33 100644 --- a/tests/README.md +++ b/tests/README.md @@ -130,7 +130,7 @@ browser (Chromium): stored and reflected XSS payloads (the same texts as the PHP file names, and uploaded SVG files opened directly. Any `alert()` or event handler that runs fails a test. `canary.spec.js` checks that the helpers really notice scripts. The other specs check behaviour of pages that needs a browser: the keyboard shortcuts of every page (`shortcuts.spec.js`: each key, the keys which are left alone while typing, with modifiers, repeated or during an input method, the list which `?` shows, the history with git, and the pages without a script), the editor (`editor.spec.js`, `autosave.spec.js`, its keys in `editor-keys.spec.js`: saving, bold, italic, links and undoing them, the preview, indenting with Tab in `editor-indent.spec.js`, the formatting toolbar in `toolbar.spec.js`: every button, the menu of the headings, the dialog for tables with its limits, tables of tab- or comma-separated lines, undoing each change in one step, the draft and the preview, the focus and the keyboard, narrow screens, the dark scheme and the editor without a script, inserting text files in `editor-import.spec.js`, dropping files and images in `dragdrop.spec.js`: the position of the drop in the text (compared with where a click puts the cursor, also after scrolling and with `caretRangeFromPoint()` of older browsers), the cursor following the drag, several files in their order, drops next to the text (preview, toolbar, buttons) which the browser must not open, the hint over the page (shown, hidden, readable in both schemes), drags of text and links which are left alone (also a real drag of selected text), images of the wiki's uploads (from the upload page, and a real drag from the preview) and of other sites, `javascript:` and `data:` addresses which are ignored, undoing, the preview and the draft, and the upload page, the preview in `preview.spec.js`: updates while typing, the button and the remembered choice, the layout on wide and narrow screens, links, errors, and payloads which must not run in it) -the search box of the toolbar (`search.spec.js`) and uploading with the dialog and the crop frame, from the editor (`editor-upload.spec.js`) and the upload page (`upload-page.spec.js`), the history of a page with git (`history.spec.js`: from the page to the versions, the changes of a version and restoring it), highlighted code blocks (`code-highlighting.spec.js`: readable in both color schemes, without violating the content security policy), and the color schemes (`dark-mode.spec.js`: contrast of the text in every view, and light mode staying as it was; `theme-switch.spec.js`: the buttons of the toolbar, with and without a script, and that the icons are drawn from their files without violating the content security policy), and phones (`mobile.spec.js`: no view wider than the screen at 320 and 390 pixels, the columns which the lists leave out there, the list of all pages in two lines per page, icons large enough to tap and form fields with text of at least 16px, and the wide screen staying as it was). +the search box of the toolbar (`search.spec.js`) and uploading with the dialog and the crop frame, from the editor (`editor-upload.spec.js`) and the upload page (`upload-page.spec.js`), the history of a page with git (`history.spec.js`: from the page to the versions, the changes of a version and restoring it), highlighted code blocks (`code-highlighting.spec.js`: readable in both color schemes, without violating the content security policy), and the color schemes (`dark-mode.spec.js`: contrast of the text in every view, and light mode staying as it was; `theme-switch.spec.js`: the buttons of the toolbar, with and without a script, and that the icons are drawn from their files without violating the content security policy), and phones (`mobile.spec.js`: no view wider than the screen at 320 and 390 pixels, the columns which the lists leave out there, the list of all pages in two lines per page, the title bar in one line, the bars hidden while the text of the editor is typed, icons large enough to tap and form fields with text of at least 16px, and the wide screen staying as it was). ``` cd tests/Browser From 727e6ab81bb147983b66cc68fdc2bd050d867107 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 20:33:27 +0000 Subject: [PATCH 3/4] Editor: the button to insert the text of a file is an icon of the toolbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Insert text from file…" was a wide text button below the text, which made the row of buttons wrap on phones (Preview on a second line). It is now an icon of the formatting toolbar, after the one to upload a file, like the other ways to insert something; the file field goes with it. The icon is new in webicons/ (insert-file: a page with an arrow into it, drawn like new.svg; check.js and preview.html updated). The text of the old button is no longer used (removed from de.php). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AFJFMPuuJS5KWXNTediQpN --- README.md | 4 ++-- locales/de.php | 1 - src/templates/editor.php | 2 -- src/templates/format-bar.php | 5 ++++- tests/Browser/editor-import.spec.js | 16 +++++++++++++++- tests/Integration/FormatBarTest.php | 2 +- tests/Integration/FormsTest.php | 5 ++++- webicons/icons/insert-file.svg | 7 +++++++ webicons/preview.html | 8 ++++---- wiki.js | 4 ++-- 10 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 webicons/icons/insert-file.svg diff --git a/README.md b/README.md index 234e862..c17ca6f 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ W2 wiki is a web-based, wiki-like notepad that you can host yourself. - Page history from git (with the git integration): the versions of a page (also from before it was renamed), an old version, what changed in it or how it differs from the current text, and restoring it in the editor - Support for renaming and deleting pages - Markdown formatting syntax help on edit page - - Formatting toolbar above the text in the editor: bold, italic, headings (level 1 to 4), links (also to pages of the wiki), bulleted and numbered lists, quotes, code (inline, or a fenced block with the cursor where the language goes), horizontal rules, tables of a chosen size (or made of selected lines separated by tabs or commas, as copied from a spreadsheet), upload and the formatting help. Each change is one step for Ctrl+Z; the toolbar is one stop of Tab, with the arrow keys between its buttons (Alt+F10 goes there from the text). Only shown with JavaScript - - Insert the text of Markdown or text files into the editor (button below the text, or drag & drop on the text); a new page gets the file's name + - Formatting toolbar above the text in the editor: bold, italic, headings (level 1 to 4), links (also to pages of the wiki), bulleted and numbered lists, quotes, code (inline, or a fenced block with the cursor where the language goes), horizontal rules, tables of a chosen size (or made of selected lines separated by tabs or commas, as copied from a spreadsheet), upload, the text of a Markdown or text file, and the formatting help. Each change is one step for Ctrl+Z; the toolbar is one stop of Tab, with the arrow keys between its buttons (Alt+F10 goes there from the text). Only shown with JavaScript + - Insert the text of Markdown or text files into the editor (button of the formatting toolbar, or drag & drop on the text); a new page gets the file's name - Live preview in the editor (button below the text): rendered by the server like the page itself (links, embeds, uploads), next to the text on wide screens and instead of it on narrow ones; the choice is remembered in the browser - Keyboard shortcuts (`?` shows the list): `/` search, `e` edit, `n` new page, `g` `h` home page, `g` `a` all pages, `h` history (with git); in the editor Ctrl+S or Ctrl+Enter save, Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+Alt+P preview, Alt+F10 formatting toolbar, Tab indents (Cmd and Option on a Mac). They only use the links of the page, and are left alone while typing; the pages work without them (and without JavaScript) - Localization support (en/de/ja/oc translations included) diff --git a/locales/de.php b/locales/de.php index d7bc580..89c503f 100644 --- a/locales/de.php +++ b/locales/de.php @@ -113,7 +113,6 @@ 'Pages which mention the name without a link:' => 'Seiten, die den Namen ohne Link erwähnen:', 'Save (Ctrl+S)' => 'Speichern (Strg+S)', 'Tab indents lines, Shift+Tab outdents them. To leave the text with Tab, press Esc first.' => 'Tab rückt Zeilen ein, Umschalt+Tab rückt sie aus. Um den Text mit Tab zu verlassen, zuerst Esc drücken.', - 'Insert text from file…' => 'Text aus Datei einfügen…', 'Insert the text of a Markdown or text file at the cursor (also by dropping the file on the text)' => 'Den Text einer Markdown- oder Textdatei an der Cursorposition einfügen (auch durch Ziehen der Datei auf den Text)', 'The file %s is larger than 2 MB and was not inserted.' => 'Die Datei %s ist größer als 2 MB und wurde nicht eingefügt.', 'The file %s is not a text file (.md, .markdown or .txt) and was not inserted.' => 'Die Datei %s ist keine Textdatei (.md, .markdown oder .txt) und wurde nicht eingefügt.', diff --git a/src/templates/editor.php b/src/templates/editor.php index ad200ad..ef052b8 100644 --- a/src/templates/editor.php +++ b/src/templates/editor.php @@ -52,8 +52,6 @@ - -

render('table-dialog') ?> diff --git a/src/templates/format-bar.php b/src/templates/format-bar.php index 98f5ec9..82b6673 100644 --- a/src/templates/format-bar.php +++ b/src/templates/format-bar.php @@ -4,7 +4,8 @@ * * The formatting toolbar directly above the text of the editor (inside the form of editor): buttons which format the * selected text or the lines of the cursor (bold, italic, headings, links, lists, quotes, code), insert a rule or a - * table (with the dialog of table-dialog), upload files, and show the Markdown help (the drawer). The buttons only work + * table (with the dialog of table-dialog), upload files, insert the text of Markdown or text files (the hidden field + * of the files to choose, see setupImport() in wiki.js), and show the Markdown help (the drawer). The buttons only work * with the script (setupFormatBar() in wiki.js), so the toolbar is hidden until the script shows it. * The buttons name their keyboard shortcut in their label (their tooltip); the arrow keys move between them, and Alt+F10 * in the text goes to them. @@ -35,5 +36,7 @@ uploads): ?> + + diff --git a/tests/Browser/editor-import.spec.js b/tests/Browser/editor-import.spec.js index fcfc08f..4562a29 100644 --- a/tests/Browser/editor-import.spec.js +++ b/tests/Browser/editor-import.spec.js @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -// Inserting Markdown and text files into the text of the editor: with the button below the text, or by dropping them +// Inserting Markdown and text files into the text of the editor: with the button of the formatting toolbar, or by dropping them const { test, expect } = require('@playwright/test'); const { savePage, gif } = require('./helpers'); @@ -38,6 +38,9 @@ test('new page: the chosen file fills the text and the title, and is saved like test('the button opens the file chooser', async ({ page }) => { await page.goto('/index.php?action=new'); + // (an icon of the formatting toolbar, after the upload button) + await expect(page.locator('#formatbar #uploadbutton + #importbutton svg.icon-insert-file')).toBeVisible(); + await expect(page.locator('.editactions input:not([type="hidden"])')).toHaveCount(3); const chooser = page.waitForEvent('filechooser'); await page.click('#importbutton'); const fileChooser = await chooser; @@ -46,6 +49,17 @@ test('the button opens the file chooser', async ({ page }) => { await expect(page.locator('#text')).toHaveValue('chosen text'); }); +test('the button inserts the file where the cursor was', async ({ page, request }) => { + await savePage(request, 'Page with a chosen part', 'before after'); + await page.goto('/index.php?action=edit&page=' + encodeURIComponent('Page with a chosen part')); + await page.evaluate(() => { const text = document.getElementById('text'); text.focus(); text.setSelectionRange(7, 7); }); + const chooser = page.waitForEvent('filechooser'); + await page.click('#importbutton'); + await (await chooser).setFiles(textFile('part.md', 'chosen ')); + await expect(page.locator('#text')).toHaveValue('before chosen after'); + await expect(page.locator('#text')).toBeFocused(); +}); + test('existing page: the text of the file is inserted at the cursor, the page keeps its name', async ({ page, request }) => { await savePage(request, 'Page with imported part', 'before after'); await page.goto('/index.php?action=edit&page=' + encodeURIComponent('Page with imported part')); diff --git a/tests/Integration/FormatBarTest.php b/tests/Integration/FormatBarTest.php index 57acd68..d091ce7 100644 --- a/tests/Integration/FormatBarTest.php +++ b/tests/Integration/FormatBarTest.php @@ -43,7 +43,7 @@ public function testButtonsNameWhatTheyDoAndTheirKeys(): void $this->assertStringContainsString('aria-label="Link to a page of the wiki: [[selected text]]">[[ ]]', $toolbar); // (every button has a name: the label of its icon, or its own) preg_match_all('#]*>(.*?)#s', $toolbar, $buttons, PREG_SET_ORDER); - $this->assertCount(17, $buttons); + $this->assertCount(18, $buttons); foreach ($buttons as $button) { $this->assertTrue(preg_match('#aria-label="[^"]+"#', $button[0]) === 1 || trim(strip_tags($button[1])) !== '', $button[0]); } diff --git a/tests/Integration/FormsTest.php b/tests/Integration/FormsTest.php index e73b097..de46969 100644 --- a/tests/Integration/FormsTest.php +++ b/tests/Integration/FormsTest.php @@ -104,7 +104,10 @@ public function testEditorHasTheButtonToInsertATextFile(): void $form = $this->form($body, 'edit'); $this->assertSame('The file %s is larger than 2 MB and was not inserted.', $form->getAttribute('data-msg-import-too-large')); $this->assertSame('The file %s is not a text file (.md, .markdown or .txt) and was not inserted.', $form->getAttribute('data-msg-import-not-text')); - $this->assertStringContainsString('assertMatchesRegularExpression('#
\n\n]*/>\n - + + + diff --git a/tests/Browser/toolbar.spec.js b/tests/Browser/toolbar.spec.js index 811773f..29b3d3c 100644 --- a/tests/Browser/toolbar.spec.js +++ b/tests/Browser/toolbar.spec.js @@ -488,7 +488,7 @@ test.describe('dark color scheme', () => { test('the buttons, the menu and the dialog are readable', async ({ page }) => { const problems = watchProblems(page); await page.goto('/index.php?action=new'); - await expectReadable(page, ['#formatbar button[data-format="wikilink"]', '#formatbar button[data-format="bold"] svg.icon']); + await expectReadable(page, ['#formatbar button[data-format="wikilink"] svg.icon', '#formatbar button[data-format="link"] svg.icon', '#formatbar button[data-format="bold"] svg.icon']); await page.click('#headingbutton'); await expectReadable(page, ['#headingmenu [data-level="1"]', '#headingmenu [data-level="4"]']); await page.keyboard.press('Escape'); diff --git a/tests/Integration/FormatBarTest.php b/tests/Integration/FormatBarTest.php index d091ce7..b4a18cb 100644 --- a/tests/Integration/FormatBarTest.php +++ b/tests/Integration/FormatBarTest.php @@ -40,7 +40,10 @@ public function testButtonsNameWhatTheyDoAndTheirKeys(): void $this->assertStringContainsString('', $toolbar); + // (links to addresses have the globe which marks them in the pages, links to pages of the wiki the chain) + $this->assertStringContainsString('