linter report expands/collapses on click; the state is saved

This commit is contained in:
tophf 2017-11-23 08:10:35 +03:00
parent 06cda0b2c1
commit 479d95711b
5 changed files with 47 additions and 21 deletions

View File

@ -235,7 +235,16 @@
</span> </span>
</div> </div>
</details> </details>
<section id="lint"><h2 i18n-text="linterIssues">: <span id="issue-count"></span><svg id="lint-help" class="svg-icon info"><use xlink:href="#svg-icon-help"/></svg></h2><div></div></section> <details id="lint">
<summary>
<h2 i18n-text="linterIssues">: <span id="issue-count"></span><!-- EAT SPACE
--><svg id="lint-help" class="svg-icon info intercepts-click">
<use xlink:href="#svg-icon-help"/>
</svg>
</h2>
</summary>
<div></div>
</details>
</div> </div>
<section id="sections"> <section id="sections">
<h2><span id="sections-heading" i18n-text="styleSectionsTitle"></span><svg id="sections-help" class="svg-icon info"><use xlink:href="#svg-icon-help"/></svg></h2> <h2><span id="sections-heading" i18n-text="styleSectionsTitle"></span><svg id="sections-help" class="svg-icon info"><use xlink:href="#svg-icon-help"/></svg></h2>

View File

@ -119,16 +119,24 @@ input:invalid {
margin-right: 0.5rem; margin-right: 0.5rem;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
} }
/* options */ /* collapsibles */
#options summary { #header summary {
align-items: center; align-items: center;
margin-left: -13px; margin-left: -13px;
cursor: pointer; cursor: pointer;
outline: none; outline: none;
} }
#options summary h2 { #header summary h2 {
display: inline-block; display: inline-block;
border-bottom: 2px dotted transparent;
} }
#header summary h2:hover {
border-color: #bbb;
}
#header summary svg {
margin-top: -3px;
}
/* options */
#options [type="number"] { #options [type="number"] {
width: 3.5em; width: 3.5em;
text-align: left; text-align: left;
@ -620,10 +628,10 @@ body[data-match-highlight="selection"] .CodeMirror-selection-highlight-scrollbar
position: relative; position: relative;
top: 0.2rem; top: 0.2rem;
} }
#lint h2 { #options:not([open]) + #lint h2 {
display: block;
cursor: default;
margin-top: 0; margin-top: 0;
}
#lint:not([open]) h2 {
margin-bottom: 0; margin-bottom: 0;
} }
#lint > div { #lint > div {
@ -632,10 +640,6 @@ body[data-match-highlight="selection"] .CodeMirror-selection-highlight-scrollbar
#lint.collapsed > div { #lint.collapsed > div {
display: none; display: none;
} }
#lint:hover > div {
margin-top: 1em;
max-height: 30vh;
}
#lint table { #lint table {
width: 100%; width: 100%;
} }

View File

@ -1434,14 +1434,26 @@ function addSections(sections, onAdded = () => {}) {
} }
} }
function setupOptionsExpand() { function initCollapsibles() {
$('#options').open = prefs.get('editor.options.expanded'); function saveStateDelayed(event) {
$('#options h2').addEventListener('click', () => { if (event.target.closest('.intercepts-click')) {
setTimeout(() => prefs.set('editor.options.expanded', $('#options').open)); event.preventDefault();
}); } else {
prefs.subscribe(['editor.options.expanded'], (key, value) => { setTimeout(saveState, 0, event.target.closest('details'));
$('#options').open = value; }
}); }
function saveState(el) {
prefs.set(`editor.${el.id}.expanded`, el.open);
}
function loadState(key, value) {
$('#' + key.split('.')[1]).open = value;
}
const collapsibles = $$('#header details');
for (const el of collapsibles) {
el.open = prefs.get(`editor.${el.id}.expanded`);
$('h2', el).addEventListener('click', saveStateDelayed);
}
prefs.subscribe(collapsibles.map(el => `editor.${el.id}.expanded`), loadState);
} }
function initHooks() { function initHooks() {
@ -1463,7 +1475,7 @@ function initHooks() {
$('#keyMap-help').addEventListener('click', showKeyMapHelp, false); $('#keyMap-help').addEventListener('click', showKeyMapHelp, false);
$('#cancel-button').addEventListener('click', goBackToManage); $('#cancel-button').addEventListener('click', goBackToManage);
setupOptionsExpand(); initCollapsibles();
initLint(); initLint();
if (!FIREFOX) { if (!FIREFOX) {

View File

@ -22,7 +22,7 @@ function createSourceEditor(style) {
appendChild: makeLink('https://github.com/openstyles/stylus/wiki/Usercss', t('externalUsercssDocument')) appendChild: makeLink('https://github.com/openstyles/stylus/wiki/Usercss', t('externalUsercssDocument'))
})); }));
setupOptionsExpand(); initCollapsibles();
const dirty = dirtyReporter(); const dirty = dirtyReporter();
dirty.onChange(() => { dirty.onChange(() => {

View File

@ -30,6 +30,7 @@ var prefs = new function Prefs() {
'editor.options': {}, // CodeMirror.defaults.* 'editor.options': {}, // CodeMirror.defaults.*
'editor.options.expanded': true, // UI element state: expanded/collapsed 'editor.options.expanded': true, // UI element state: expanded/collapsed
'editor.lint.expanded': true, // UI element state: expanded/collapsed
'editor.lineWrapping': true, // word wrap 'editor.lineWrapping': true, // word wrap
'editor.smartIndent': true, // 'smart' indent 'editor.smartIndent': true, // 'smart' indent
'editor.indentWithTabs': false, // smart indent with tabs 'editor.indentWithTabs': false, // smart indent with tabs