From 5348d33920a0530dec9ee0b2df3ffd5f431cd83f Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 7 Jan 2022 11:28:28 +0300 Subject: [PATCH] Shift key to set all widths --- _locales/en/messages.json | 4 ++++ edit.html | 2 +- install-usercss.html | 2 +- js/dom.js | 20 +++++++++++--------- js/header-resizer.js | 25 +++++++++++++++---------- js/prefs.js | 8 +++++--- manage.html | 2 +- 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a6c4d3c2..b363ade1 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -504,6 +504,10 @@ "gettingStyles": { "message": "Getting all styles..." }, + "headerResizerHint": { + "message": "Holding Shift key dragging will set the new size in all UI pages", + "description": "Tooltip for the header panel resizer" + }, "helpAlt": { "message": "Help", "description": "Alternate text for help buttons" diff --git a/edit.html b/edit.html index 202ce287..b862d77f 100644 --- a/edit.html +++ b/edit.html @@ -466,7 +466,7 @@ -
+
-
+
diff --git a/js/dom.js b/js/dom.js index 5002e3cb..7a4deb19 100644 --- a/js/dom.js +++ b/js/dom.js @@ -471,18 +471,20 @@ const dom = {}; } // set language for a) CSS :lang pseudo and b) hyphenation elHtml.setAttribute('lang', chrome.i18n.getUILanguage()); - // set header width and export stuff via `dom.headerResizer` - if (/^.(edit|manage|install)/.test(location.pathname)) { - const prefId = `${RegExp.$1 === 'edit' ? 'editor' : RegExp.$1}.headerWidth`; - const HR = dom.headerResizer = { - prefId, - setDomProp(width) { - width = Math.round(Math.max(200, Math.min(innerWidth / 2, width))); + // set up header width resizer + const HW = 'headerWidth.'; + const HWprefId = HW + location.pathname.match(/^.(\w*)/)[1]; + if (prefs.knownKeys.includes(HWprefId)) { + Object.assign(dom, { + HW, + HWprefId, + setHWProp(width) { + width = Math.round(Math.max(200, Math.min(innerWidth / 2, Number(width) || 0))); elHtml.style.setProperty('--header-width', width + 'px'); return width; }, - }; - prefs.ready.then(() => HR.setDomProp(prefs.get(prefId))); + }); + prefs.ready.then(() => dom.setHWProp(prefs.get(HWprefId))); lazyScripts.push('/js/header-resizer'); } // add favicon in FF diff --git a/js/header-resizer.js b/js/header-resizer.js index a08c59ed..27c30311 100644 --- a/js/header-resizer.js +++ b/js/header-resizer.js @@ -4,16 +4,14 @@ 'use strict'; (() => { - const HR = dom.headerResizer; - const el = $('#header-resizer'); let curW, offset, active; - prefs.subscribe(HR.prefId, (key, val) => { + prefs.subscribe(dom.HWprefId, (key, val) => { if (!active && val !== curW) { getCurWidth(); setWidth(val); } }); - el.onmousedown = e => { + $('#header-resizer').onmousedown = e => { if (e.button) return; getCurWidth(); offset = curW - e.clientX; @@ -28,9 +26,10 @@ || $('#header').offsetWidth; } - function resize({clientX: x}) { - if (setWidth(offset + x)) { - debounce(save, 250); + /** @param {MouseEvent} e */ + function resize(e) { + if (setWidth(offset + e.clientX)) { + debounce(save, 250, e.shiftKey); } } @@ -41,12 +40,18 @@ active = false; } - function save() { - prefs.set(HR.prefId, curW); + function save(all) { + if (all) { + for (const k of prefs.knownKeys) { + if (k.startsWith(dom.HW)) prefs.set(k, curW); + } + } else { + prefs.set(dom.HWprefId, curW); + } } function setWidth(w) { - const delta = (w = HR.setDomProp(w)) - curW; + const delta = (w = dom.setHWProp(w)) - curW; if (delta) { curW = w; for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) { diff --git a/js/prefs.js b/js/prefs.js index 034c07f1..a4f638b5 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -123,9 +123,11 @@ 'badgeDisabled': '#8B0000', // badge background color when disabled 'badgeNormal': '#006666', // badge background color - 'editor.headerWidth': 280, - 'install.headerWidth': 280, - 'manage.headerWidth': 280, + /* Using separate values instead of a single {} to ensure type control. + * Sub-key is the first word in the html's file name. */ + 'headerWidth.edit': 280, + 'headerWidth.install': 280, + 'headerWidth.manage': 280, 'popupWidth': 246, // popup width in pixels diff --git a/manage.html b/manage.html index 597b4098..e51d29fa 100644 --- a/manage.html +++ b/manage.html @@ -354,7 +354,7 @@
-
+