Skip to content

Commit 533c711

Browse files
committed
Add a url upgrader for the changed sourceView query parameter
1 parent 743db5c commit 533c711

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/app-logic/url-handling.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
} from '../utils/uintarray-encoding';
4949
import { tabSlugs } from '../app-logic/tabs-handling';
5050

51-
export const CURRENT_URL_VERSION = 11;
51+
export const CURRENT_URL_VERSION = 12;
5252

5353
/**
5454
* This static piece of state might look like an anti-pattern, but it's a relatively
@@ -1162,6 +1162,34 @@ const _upgraders: {
11621162
processedLocation.query = {};
11631163
}
11641164
},
1165+
[12]: (
1166+
processedLocation: ProcessedLocationBeforeUpgrade,
1167+
profile?: Profile
1168+
) => {
1169+
// This version changes the source view parameter from 'sourceView' (filename
1170+
// string) to 'sourceViewIndex' (IndexIntoSourceTable). If we can't convert
1171+
// the filename to a source index, so we just remove the sourceView parameter.
1172+
const { query } = processedLocation;
1173+
if (!('sourceView' in query) || !profile || !profile.shared.sources) {
1174+
return;
1175+
}
1176+
1177+
// Try to find the source index for the given filename
1178+
const filename = query.sourceView;
1179+
const { sources, stringArray } = profile.shared;
1180+
1181+
// Find the filename string index
1182+
const filenameStringIndex = stringArray.indexOf(filename);
1183+
if (filenameStringIndex !== -1) {
1184+
// Find the source index with this filename
1185+
const sourceIndex = sources.filename.indexOf(filenameStringIndex);
1186+
if (sourceIndex !== -1) {
1187+
query.sourceViewIndex = sourceIndex;
1188+
}
1189+
}
1190+
// Remove the old sourceView parameter regardless of whether we found a match
1191+
delete query.sourceView;
1192+
},
11651193
};
11661194

11671195
for (let destVersion = 1; destVersion <= CURRENT_URL_VERSION; destVersion++) {

0 commit comments

Comments
 (0)