PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | js/services/settings/tabs.ts +13 -10 3.10.1 → 4.0.0-beta.2 View file →
@@ -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 }