fix: disable detach when only one tab is open
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -1336,6 +1336,8 @@ body.has-tabs {{ --chrome-top: 50px; }}
|
|||||||
font-size: 13px; cursor: pointer;
|
font-size: 13px; cursor: pointer;
|
||||||
}}
|
}}
|
||||||
.tab-menu button:hover {{ background: #f2f2f2; }}
|
.tab-menu button:hover {{ background: #f2f2f2; }}
|
||||||
|
.tab-menu button:disabled {{ opacity: .42; cursor: default; }}
|
||||||
|
.tab-menu button:disabled:hover {{ background: transparent; }}
|
||||||
.tab-open {{
|
.tab-open {{
|
||||||
width: 31px; height: 31px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 7px;
|
width: 31px; height: 31px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 7px;
|
||||||
color: #666; background: transparent; cursor: pointer; font: 20px/1 -apple-system, sans-serif;
|
color: #666; background: transparent; cursor: pointer; font: 20px/1 -apple-system, sans-serif;
|
||||||
@@ -1462,6 +1464,7 @@ body.empty .toolbar {{ display: none !important; }}
|
|||||||
.tab-menu {{ background: #2a2a2a; border-color: #444; box-shadow: 0 8px 24px rgba(0,0,0,.45); }}
|
.tab-menu {{ background: #2a2a2a; border-color: #444; box-shadow: 0 8px 24px rgba(0,0,0,.45); }}
|
||||||
.tab-menu button {{ color: #ddd; }}
|
.tab-menu button {{ color: #ddd; }}
|
||||||
.tab-menu button:hover {{ background: rgba(255,255,255,.08); }}
|
.tab-menu button:hover {{ background: rgba(255,255,255,.08); }}
|
||||||
|
.tab-menu button:disabled:hover {{ background: transparent; }}
|
||||||
.missing-file p {{ color: #aaa; }}
|
.missing-file p {{ color: #aaa; }}
|
||||||
.missing-actions button {{ background: #292929; border-color: #444; color: #ddd; }}
|
.missing-actions button {{ background: #292929; border-color: #444; color: #ddd; }}
|
||||||
.missing-actions button:hover {{ background: #333; }}
|
.missing-actions button:hover {{ background: #333; }}
|
||||||
@@ -1553,6 +1556,7 @@ body.editing #app {{ max-width: none; padding: 0; }}
|
|||||||
var ta = document.getElementById('editor');
|
var ta = document.getElementById('editor');
|
||||||
var dirty = false;
|
var dirty = false;
|
||||||
var activeTabId = 0;
|
var activeTabId = 0;
|
||||||
|
var tabCount = 0;
|
||||||
var pendingAutosaveTimer = 0;
|
var pendingAutosaveTimer = 0;
|
||||||
var autosavePaused = false;
|
var autosavePaused = false;
|
||||||
var saveBlocked = false;
|
var saveBlocked = false;
|
||||||
@@ -1643,6 +1647,7 @@ body.editing #app {{ max-width: none; padding: 0; }}
|
|||||||
if (!tabMenu) return;
|
if (!tabMenu) return;
|
||||||
tabMenuTargetId = id;
|
tabMenuTargetId = id;
|
||||||
tabMenu.hidden = false;
|
tabMenu.hidden = false;
|
||||||
|
if (tabMenuNewWindow) tabMenuNewWindow.disabled = tabCount <= 1;
|
||||||
tabMenu.style.left = '0px';
|
tabMenu.style.left = '0px';
|
||||||
tabMenu.style.top = '0px';
|
tabMenu.style.top = '0px';
|
||||||
var rect = tabMenu.getBoundingClientRect();
|
var rect = tabMenu.getBoundingClientRect();
|
||||||
@@ -1652,6 +1657,7 @@ body.editing #app {{ max-width: none; padding: 0; }}
|
|||||||
tabMenu.style.top = top + 'px';
|
tabMenu.style.top = top + 'px';
|
||||||
}}
|
}}
|
||||||
function detachTab(id) {{
|
function detachTab(id) {{
|
||||||
|
if (tabCount <= 1) return;
|
||||||
if (saveBlocked) {{
|
if (saveBlocked) {{
|
||||||
window.alert(window.__mdPreviewCannotSave || 'Discard unsaved changes?');
|
window.alert(window.__mdPreviewCannotSave || 'Discard unsaved changes?');
|
||||||
return;
|
return;
|
||||||
@@ -2087,6 +2093,8 @@ body.editing #app {{ max-width: none; padding: 0; }}
|
|||||||
window.__setTabs = function(tabs) {{
|
window.__setTabs = function(tabs) {{
|
||||||
hideTabMenu();
|
hideTabMenu();
|
||||||
tabs = Array.isArray(tabs) ? tabs : [];
|
tabs = Array.isArray(tabs) ? tabs : [];
|
||||||
|
tabCount = tabs.length;
|
||||||
|
if (tabMenuNewWindow) tabMenuNewWindow.disabled = tabCount <= 1;
|
||||||
tabsEl.textContent = '';
|
tabsEl.textContent = '';
|
||||||
activeTabId = 0;
|
activeTabId = 0;
|
||||||
document.body.classList.toggle('has-tabs', tabs.length > 0);
|
document.body.classList.toggle('has-tabs', tabs.length > 0);
|
||||||
@@ -2682,6 +2690,9 @@ mod tests {
|
|||||||
assert!(page.contains("'external-change:' + (dirty ? 'dirty' : 'clean')"));
|
assert!(page.contains("'external-change:' + (dirty ? 'dirty' : 'clean')"));
|
||||||
assert!(page.contains("(e.key === 'n' || e.key === 'N')"));
|
assert!(page.contains("(e.key === 'n' || e.key === 'N')"));
|
||||||
assert!(page.contains("id=\"doc-stats\""));
|
assert!(page.contains("id=\"doc-stats\""));
|
||||||
|
assert!(page.contains("id=\"tab-menu\""));
|
||||||
|
assert!(page.contains("tabCount = tabs.length"));
|
||||||
|
assert!(page.contains("tabMenuNewWindow.disabled = tabCount <= 1"));
|
||||||
assert!(page.contains("updateDocumentStats"));
|
assert!(page.contains("updateDocumentStats"));
|
||||||
assert!(page.contains("restoreScrollProgress"));
|
assert!(page.contains("restoreScrollProgress"));
|
||||||
assert!(page.contains("postMessage('zoom:' + zoomPercent)"));
|
assert!(page.contains("postMessage('zoom:' + zoomPercent)"));
|
||||||
|
|||||||
Reference in New Issue
Block a user