Skip to content

Commit

Permalink
Fix regression at "Refresh" feature partially
Browse files Browse the repository at this point in the history
The application is supposed to stay inside the same document (after
some navigation was done) and to keep the scroll position. This got
broken years ago with commit 4135298

Now the application stays in the same document again. It was given up
to fix the scroll position problem. The logic handling will be
completely reimplemented in "next" major version.
  • Loading branch information
c3er committed Sep 2, 2024
1 parent 722c993 commit 3a0ffdd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
11 changes: 8 additions & 3 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function createMainMenu() {
{
label: "&Refresh",
accelerator: "F5",
id: "refresh",
click() {
reload(false)
},
Expand Down Expand Up @@ -506,11 +507,15 @@ electron.app.on("open-file", (event, path) => {
})

ipc.listen(ipc.messages.finishLoad, () => {
settings.init(_mainMenu, determineCurrentFilePath())
const filePath = determineCurrentFilePath()
settings.init(_mainMenu, filePath)
zoom.init()

const filePath = _finderFilePath ?? _cliArgs.filePath
openFile(filePath, _cliArgs.internalTarget, encodingLib.load(filePath))
if (navigation.hasCurrentLocation()) {
navigation.reloadCurrent(_scrollPosition)
} else {
openFile(filePath, _cliArgs.internalTarget, encodingLib.load(filePath))
}

if (_finderFilePath) {
_mainWindow.setBounds(loadDocumentSettings().windowPosition)
Expand Down
36 changes: 25 additions & 11 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const toc = require("../app/lib/tocMain")

const electron = playwright._electron

const DEFAULT_TIMEOUT = 3000

let _app
let _page

Expand All @@ -36,26 +38,27 @@ async function waitForWindowLoaded() {
await _page.locator("#loading-indicator #loaded").waitFor({ state: "attached", timeout: 5000 })
}

async function startApp(documentPath) {
const defaultTimeout = 3000

_app = await electron.launch({
args: [path.join(__dirname, ".."), documentPath, "--test", mocking.dataDir],
executablePath: electronPath,
})
_app.context().setDefaultTimeout(defaultTimeout)

async function initPage() {
_page = await _app.firstWindow()
_page.on("console", msg => addMessage(msg.text()))
_page.on("crash", () => assert.fail("Crash happened"))
_page.on("pageerror", error => assert.fail(`Page error: ${error.stack}`))

_page.setDefaultTimeout(defaultTimeout)
_page.setDefaultNavigationTimeout(defaultTimeout)
_page.setDefaultTimeout(DEFAULT_TIMEOUT)
_page.setDefaultNavigationTimeout(DEFAULT_TIMEOUT)

await waitForWindowLoaded()
}

async function startApp(documentPath) {
_app = await electron.launch({
args: [path.join(__dirname, ".."), documentPath, "--test", mocking.dataDir],
executablePath: electronPath,
})
_app.context().setDefaultTimeout(DEFAULT_TIMEOUT)
await initPage()
}

async function restartApp(documentPath) {
await _app.close()
await startApp(documentPath ?? lib.DEFAULT_DOCUMENT_PATH)
Expand Down Expand Up @@ -726,6 +729,17 @@ describe("Integration tests with their own app instance each", () => {
)
})
})

describe("Refresh", () => {
it("stays in same document", async () => {
await _page.getByText("Link to README.md", { exact: true }).click()
assert((await _page.title()).includes("README.md"))

await clickMenuItem("refresh")
await initPage()
assert((await _page.title()).includes("README.md"))
})
})
})

describe("Integration tests with special documents", () => {
Expand Down

0 comments on commit 3a0ffdd

Please sign in to comment.