Skip to content

Commit 08cc53f

Browse files
committed
fixup! Implement last opened functionality
1 parent 2fbb43f commit 08cc53f

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/node/routes/vscode.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,31 @@ export class CodeServerRouteWrapper {
3434

3535
// Ew means the workspace was closed so clear the last folder/workspace.
3636
const { query } = await settings.read()
37-
if (req.query.ew) {
38-
delete query.folder
39-
delete query.workspace
40-
}
37+
if (query) {
38+
if (req.query.ew) {
39+
delete query.folder
40+
delete query.workspace
41+
}
4142

42-
// Redirect to the last folder/workspace if nothing else is opened.
43-
if (
44-
!req.query.folder &&
45-
!req.query.workspace &&
46-
(query.folder || query.workspace) &&
47-
!req.args["ignore-last-opened"] // This flag disables this behavior.
48-
) {
49-
return redirect(req, res, "", {
50-
folder: query.folder,
51-
workspace: query.workspace,
52-
})
43+
// Redirect to the last folder/workspace if nothing else is opened.
44+
if (
45+
!req.query.folder &&
46+
!req.query.workspace &&
47+
(query.folder || query.workspace) &&
48+
!req.args["ignore-last-opened"] // This flag disables this behavior.
49+
) {
50+
// Redirect to the same page but with the query parameters attached
51+
// (preserving the trailing slash if any).
52+
return redirect(req, res, req.baseUrl + (req.originalUrl.endsWith("/") ? "/" : ""), {
53+
folder: query.folder,
54+
workspace: query.workspace,
55+
})
56+
}
5357
}
5458

5559
// Store the query parameters so we can use them on the next load. This
5660
// also allows users to create functionality around query parameters.
57-
settings.write({ query: req.query })
61+
await settings.write({ query: req.query })
5862

5963
next()
6064
}

src/node/settings.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ export interface UpdateSettings {
5454
* Global code-server settings.
5555
*/
5656
export interface CoderSettings extends UpdateSettings {
57-
lastVisited: {
58-
url: string
59-
workspace: boolean
60-
}
61-
query: Query
57+
query?: Query
6258
}
6359

6460
/**

0 commit comments

Comments
 (0)