Skip to content

Commit a8b3d5e

Browse files
authored
Enable forcing a specific tab with query parameters (#11681)
Fixes flutter/devtools#8845
1 parent 7f1a604 commit a8b3d5e

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

firebase.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@
711711
{ "source": "/to/integrate-android-archive", "destination": "/add-to-app/android/project-setup", "type": 301 },
712712
{ "source": "/to/integration-test-on-web", "destination": "/testing/integration-tests#test-in-a-web-browser", "type": 301 },
713713
{ "source": "/to/integration-testing", "destination": "/cookbook/testing/integration/introduction", "type": 301 },
714-
{ "source": "/to/intellij-setup", "destination": "/get-started/editor?tab=androidstudio", "type": 301 },
714+
{ "source": "/to/intellij-setup", "destination": "/get-started/editor/?tab-save-vs-code-vs-intellij=android-studio-and-intellij", "type": 301 },
715715
{ "source": "/to/internationalization", "destination": "/ui/accessibility-and-internationalization/internationalization", "type": 301 },
716716
{ "source": "/to/ios-app-signing", "destination": "/deployment/ios#review-xcode-project-settings", "type": 301 },
717717
{ "source": "/to/ios-create-flutter-engine", "destination": "/add-to-app/ios/add-flutter-screen#create-a-flutterengine", "type": 301 },
@@ -751,9 +751,9 @@
751751
{ "source": "/to/troubleshoot-devices", "destination": "/get-started/install", "type": 301 },
752752
{ "source": "/to/unbounded-constraints", "destination": "/ui/layout/constraints#unbounded", "type": 301 },
753753
{ "source": "/to/unit-testing", "destination": "/cookbook/testing/unit/introduction", "type": 301 },
754-
{ "source": "/to/update-linux-path", "destination": "/get-started/install/linux/android?tab=download#add-flutter-to-your-path", "type": 301 },
755-
{ "source": "/to/update-macos-path", "destination": "/get-started/install/macos/mobile-ios?tab=download#add-flutter-to-your-path", "type": 301 },
756-
{ "source": "/to/update-windows-path", "destination": "/get-started/install/windows/mobile?tab=download#update-your-windows-path-variable", "type": 301 },
754+
{ "source": "/to/update-linux-path", "destination": "/get-started/install/linux/android?tab-save-vs-code-or-download=download-and-install#add-flutter-to-your-path", "type": 301 },
755+
{ "source": "/to/update-macos-path", "destination": "/get-started/install/macos/mobile-ios?tab-save-vs-code-or-download=download-and-install#add-flutter-to-your-path", "type": 301 },
756+
{ "source": "/to/update-windows-path", "destination": "/get-started/install/windows/mobile?tab-save-vs-code-or-download=download-and-install#update-your-windows-path-variable", "type": 301 },
757757
{ "source": "/to/use-mirror-site", "destination": "/community/china#configure-your-machine-to-use-a-mirror-site", "type": 301 },
758758
{ "source": "/to/use-profile-mode", "destination": "/perf/ui-performance#run-in-profile-mode", "type": 301 },
759759
{ "source": "/to/wasm", "destination": "/platform-integration/web/wasm", "type": 301 },

src/content/assets/js/tabs.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/**
2-
* Set up interactivity of tabs created with the `{% tabs %}` shortcode.
3-
*/
1+
/** Set up interactivity of tabs created with the `{% tabs %}` shortcode. */
42
function setupTabs() {
3+
_applyFromQueryParameters();
4+
55
const tabsWrappers = document.querySelectorAll('.tabs-wrapper');
66

77
tabsWrappers.forEach(function (tabWrapper) {
@@ -48,6 +48,23 @@ function setupTabs() {
4848
});
4949
}
5050

51+
/** Apply force overrides from query parameters to saved tabs. */
52+
function _applyFromQueryParameters() {
53+
const currentUrl = new URL(window.location.href);
54+
const searchParams = currentUrl.searchParams;
55+
const paramsToDelete = [];
56+
57+
searchParams.forEach((value, key) => {
58+
if (key.startsWith('tab-save-')) {
59+
localStorage.setItem(key, value);
60+
paramsToDelete.push(key);
61+
}
62+
});
63+
64+
paramsToDelete.forEach(key => searchParams.delete(key));
65+
window.history.replaceState({}, '', currentUrl.toString());
66+
}
67+
5168
function _clearActiveTabs(tabs) {
5269
tabs.forEach(function (tab) {
5370
tab.classList.remove('active');

src/content/get-started/editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ to [Write your first Flutter app][].
3737

3838
[Write your first Flutter app]: /get-started/codelab
3939

40-
{% tabs %}
40+
{% tabs "vs-code-vs-intellij" %}
4141
{% tab "Visual Studio Code" %}
4242

4343
## Install VS Code

0 commit comments

Comments
 (0)