From 51e56110e8dfd1b9691adfdb91feefd3f7f611db Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 10 Jan 2022 07:30:22 +0300 Subject: [PATCH 1/3] parserlib: color-scheme, scrollbar-gutter, transforms --- js/csslint/parserlib.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/csslint/parserlib.js b/js/csslint/parserlib.js index cdef79a3..2bd75ada 100644 --- a/js/csslint/parserlib.js +++ b/js/csslint/parserlib.js @@ -195,7 +195,7 @@ self.parserlib = (() => { 'color-interpolation-filters': 'auto | sRGB | linearRGB', 'color-profile': 1, 'color-rendering': 'auto | optimizeSpeed | optimizeQuality', - 'color-scheme': 'normal | [ light | dark ]+', + 'color-scheme': 'normal | [ light | dark | ]+ && only?', 'column-count': ' | auto', 'column-fill': 'auto | balance', 'column-gap': '', @@ -522,6 +522,7 @@ self.parserlib = (() => { 'scroll-snap-type': 'none | [ x | y | block | inline | both ] [ mandatory | proximity ]?', 'scrollbar-color': 'auto | dark | light | {2}', + 'scrollbar-gutter': 'auto | [ [ stable | always ] && both-edges? && force? ] || match-parent', 'scrollbar-width': 'auto | thin | none', 'shape-inside': 'auto | outside-shape | [ || shape-box ] | | display', 'shape-rendering': 'auto | optimizeSpeed | crispEdges | geometricPrecision', @@ -983,12 +984,12 @@ self.parserlib = (() => { 'matrix( #{6} ) | ' + 'matrix3d( #{16} ) | ' + 'perspective( | none ) | ' + - 'rotate( ) | ' + + 'rotate( | none ) | ' + 'rotate3d( #{3} , ) | ' + 'rotateX( ) | ' + 'rotateY( ) | ' + 'rotateZ( ) | ' + - 'scale( [ ]#{1,2} ) | ' + + 'scale( [ ]#{1,2} | none ) | ' + 'scale3d( #{3} ) | ' + 'scaleX( ) | ' + 'scaleY( ) | ' + @@ -996,7 +997,7 @@ self.parserlib = (() => { 'skew( [ , ]? ) | ' + 'skewX( ) | ' + 'skewY( ) | ' + - 'translate( #{1,2} ) | ' + + 'translate( #{1,2} | none ) | ' + 'translate3d( #{2} , ) | ' + 'translateX( ) | ' + 'translateY( ) | ' + From ba9d904ccc96cfc6b97356562fd96c38f20da058 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 10 Jan 2022 17:57:46 +0300 Subject: [PATCH 2/3] don't rebuild editor DOM on save, fixes #1380 --- edit/sections-editor.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/edit/sections-editor.js b/edit/sections-editor.js index deba1520..6326da8a 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -108,9 +108,8 @@ function SectionsEditor() { return; } newStyle = await API.styles.editSave(newStyle); - destroyRemovedSections(); sessionStore.justEditedStyleId = newStyle.id; - editor.replaceStyle(newStyle, false); + dirty.clear(); }, scrollToEditor(cm) { @@ -453,18 +452,6 @@ function SectionsEditor() { return true; } - function destroyRemovedSections() { - for (let i = 0; i < sections.length;) { - if (!sections[i].removed) { - i++; - continue; - } - sections[i].destroy(); - sections[i].el.remove(); - sections.splice(i, 1); - } - } - function updateMeta() { $('#name').value = style.customName || style.name || ''; $('#enabled').checked = style.enabled !== false; From 6e4fc3236eca8eb2f0c9a741ad12920c8191ad60 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 10 Jan 2022 19:12:29 +0300 Subject: [PATCH 3/3] confirm reload in sectioned editor --- edit/base.js | 1 + edit/edit.js | 25 ++++++++++++++++--------- edit/sections-editor.js | 14 +++++++++----- edit/source-editor.js | 4 +--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/edit/base.js b/edit/base.js index 0764d8d9..582f43d7 100644 --- a/edit/base.js +++ b/edit/base.js @@ -33,6 +33,7 @@ const editor = { /** @type {'customName'|'name'} */ nameTarget: 'name', previewDelay: 200, // Chrome devtools uses 200 + saving: false, scrollInfo: null, cancel: () => location.assign('/manage.html'), diff --git a/edit/edit.js b/edit/edit.js index da4771f8..aa959128 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -61,19 +61,11 @@ baseInit.ready.then(async () => { //#endregion //#region events -const IGNORE_UPDATE_REASONS = [ - 'editPreview', - 'editPreviewEnd', - 'editSave', - // https://github.com/openstyles/stylus/issues/807 is closed without fix - // 'config, -]; - msg.onExtension(request => { const {style} = request; switch (request.method) { case 'styleUpdated': - if (editor.style.id === style.id && !IGNORE_UPDATE_REASONS.includes(request.reason)) { + if (editor.style.id === style.id) { handleExternalUpdate(request); } break; @@ -89,6 +81,14 @@ msg.onExtension(request => { }); async function handleExternalUpdate({style, reason}) { + if (reason === 'editPreview' || + reason === 'editPreviewEnd') { + return; + } + if (reason === 'editSave' && editor.saving) { + editor.saving = false; + return; + } if (reason === 'toggle') { if (editor.dirty.isDirty()) { editor.toggleStyle(style.enabled); @@ -191,6 +191,13 @@ window.on('beforeunload', e => { } }, + async save() { + if (dirty.isDirty()) { + editor.saving = true; + await editor.saveImpl(); + } + }, + toggleStyle(enabled = !style.enabled) { $('#enabled').checked = enabled; editor.updateEnabledness(enabled); diff --git a/edit/sections-editor.js b/edit/sections-editor.js index 6326da8a..214a6a73 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -7,6 +7,7 @@ /* global editor */ /* global linterMan */ /* global prefs */ +/* global styleSectionsEqual */ // sections-util.js /* global t */// localization.js 'use strict'; @@ -86,9 +87,15 @@ function SectionsEditor() { }, async replaceStyle(newStyle) { + const sameCode = styleSectionsEqual(newStyle, getModel()); + if (!sameCode && !await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) { + return; + } dirty.clear(); // FIXME: avoid recreating all editors? - await initSections(newStyle.sections, {replace: true}); + if (!sameCode) { + await initSections(newStyle.sections, {replace: true}); + } Object.assign(style, newStyle); editor.updateClass(); updateMeta(); @@ -99,10 +106,7 @@ function SectionsEditor() { updateLivePreview(); }, - async save() { - if (!dirty.isDirty()) { - return; - } + async saveImpl() { let newStyle = getModel(); if (!validate(newStyle)) { return; diff --git a/edit/source-editor.js b/edit/source-editor.js index 9c7a1415..dc5e1388 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -61,8 +61,7 @@ function SourceEditor() { cm.focus(); } }, - async save() { - if (!dirty.isDirty()) return; + async saveImpl() { const sourceCode = cm.getValue(); try { const {customName, enabled, id} = style; @@ -221,7 +220,6 @@ function SourceEditor() { return; } - // TODO: also confirm in sections-editor? if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) { updateEnvironment(); if (!sameCode) {