fix calc
This commit is contained in:
parent
9e8f15b2bd
commit
eda3fb18fd
|
@ -6,26 +6,26 @@
|
||||||
(function HeaderResizer() {
|
(function HeaderResizer() {
|
||||||
const PREF_ID = 'editor.headerWidth';
|
const PREF_ID = 'editor.headerWidth';
|
||||||
const el = $('#header-resizer');
|
const el = $('#header-resizer');
|
||||||
let lastW, lastX;
|
let curW, offset;
|
||||||
prefs.subscribe(PREF_ID, (key, val) => {
|
prefs.subscribe(PREF_ID, (key, val) => {
|
||||||
setLastWidth();
|
rememberCurWidth();
|
||||||
setWidth(val);
|
setWidth(val);
|
||||||
});
|
});
|
||||||
el.onmousedown = e => {
|
el.onmousedown = e => {
|
||||||
if (e.button) return;
|
if (e.button) return;
|
||||||
setLastWidth();
|
rememberCurWidth();
|
||||||
lastX = e.clientX;
|
offset = curW - e.clientX;
|
||||||
document.body.classList.add('resizing-h');
|
document.body.classList.add('resizing-h');
|
||||||
document.on('mousemove', resize);
|
document.on('mousemove', resize);
|
||||||
document.on('mouseup', resizeStop);
|
document.on('mouseup', resizeStop);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function rememberCurWidth() {
|
||||||
|
curW = $('#header').offsetWidth;
|
||||||
|
}
|
||||||
|
|
||||||
function resize({clientX: x}) {
|
function resize({clientX: x}) {
|
||||||
const w = setWidth(lastW + x - lastX);
|
prefs.set(PREF_ID, setWidth(offset + x));
|
||||||
if (!w) return;
|
|
||||||
lastW = w;
|
|
||||||
lastX = x;
|
|
||||||
prefs.set(PREF_ID, w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeStop() {
|
function resizeStop() {
|
||||||
|
@ -34,17 +34,15 @@
|
||||||
document.body.classList.remove('resizing-h');
|
document.body.classList.remove('resizing-h');
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLastWidth() {
|
|
||||||
lastW = $('#header').clientWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @returns {number|void} new width in case it's different, otherwise void */
|
/** @returns {number|void} new width in case it's different, otherwise void */
|
||||||
function setWidth(w) {
|
function setWidth(w) {
|
||||||
const delta = (w = editor.updateHeaderWidth(w)) - lastW;
|
const delta = (w = editor.updateHeaderWidth(w)) - curW;
|
||||||
if (!delta) return;
|
if (delta) {
|
||||||
|
curW = w;
|
||||||
for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) {
|
for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) {
|
||||||
el.style.width = parseFloat(el.style.width) - delta + 'px';
|
el.style.width = parseFloat(el.style.width) - delta + 'px';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user