| @@ -18,13 +18,14 @@ | ||
| 18 | 18 | document.getElementById('version-switch-warning')?.classList.add('hidden') |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -// Refresh the editor preview if we're viewing the editor section. | |
| 23 | -const refreshEditorPreview = (section: string) => { | |
| 24 | - if ('editor' === section) { | |
| 25 | - window.code_snippets_editor_preview?.codemirror.refresh() | |
| 26 | - } | |
| 22 | +// Refresh the editor preview whenever tabs change. CodeMirror measures itself | |
| 23 | +// as zero-height while its container is hidden, so it has to be told to | |
| 24 | +// remeasure once the section holding it becomes visible. Keying this to a | |
| 25 | +// specific section name meant the preview rendered blank if that name changed. | |
| 26 | +const refreshEditorPreview = () => { | |
| 27 | + window.code_snippets_editor_preview?.codemirror.refresh() | |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | // Update the http referer value so that any redirections lead back to this tab. |
| 30 | 31 | const updateHttpReferer = (section: string) => { |
| @@ -70,15 +71,17 @@ | ||
| 70 | 71 | const tabs = tabsWrapper.querySelectorAll('.snippet-type-link') |
| 71 | 72 | |
| 72 | 73 | for (const tab of tabs) { |
| 73 | 74 | tab.addEventListener('click', event => { |
| 74 | - event.preventDefault() | |
| 75 | 75 | const section = tab.getAttribute('data-section') |
| 76 | 76 | |
| 77 | - if (section) { | |
| 78 | - selectTab(tabsWrapper, tab, section) | |
| 79 | - refreshEditorPreview(section) | |
| 80 | - updateHttpReferer(section) | |
| 77 | + if (!section || !document.querySelector(`.settings-section.${section}-settings`)) { | |
| 78 | + return | |
| 81 | 79 | } |
| 80 | + | |
| 81 | + event.preventDefault() | |
| 82 | + selectTab(tabsWrapper, tab, section) | |
| 83 | + refreshEditorPreview() | |
| 84 | + updateHttpReferer(section) | |
| 82 | 85 | }) |
| 83 | 86 | } |
| 84 | 87 | } |