From c3472207bfc1c72223373ca455723f2236fa0edf Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 22 Jun 2015 22:03:28 +0300 Subject: [PATCH] Editor: add Undo button to CSS-beautifier --- _locales/en/messages.json | 8 ++++++++ edit.html | 8 +++++++- edit.js | 13 ++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4b1ee918..b594d71f 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -319,6 +319,14 @@ "message": "(Stylish does not work on pages like this.)", "description": "Note in the toolbar pop-up when on a URL Stylish can't affect" }, + "undo": { + "message": "Undo", + "description": "Button label" + }, + "undoGlobal": { + "message": "Undo (global)", + "description": "CSS-beautify global Undo button label" + }, "updateCheckFailBadResponseCode": { "message": "Update failed - server responded with code $code$.", "description": "Text that displays when an update check failed because the response code indicates an error", diff --git a/edit.html b/edit.html index d7ae3780..c387fe53 100644 --- a/edit.html +++ b/edit.html @@ -330,6 +330,12 @@ .beautify-options div[newline="true"] + div span[indent] { padding-left: 2rem; } + .beautify-options:after { + clear: both; + display: block; + content: " "; + height: 1rem; + } .beautify-options span { font-weight: bold; } @@ -447,7 +453,7 @@
-
+
diff --git a/edit.js b/edit.js index 52cdd3bc..974714dc 100644 --- a/edit.js +++ b/edit.js @@ -828,6 +828,7 @@ function gotoLintIssue(event) { } function beautify(event) { + var undoCount = 1; if (exports.css_beautify) { // thanks to csslint's definition of 'exports' doBeautify(); } else { @@ -860,7 +861,15 @@ function beautify(event) { optionHtml("border: none;", "newline_between_properties", true) + optionHtml("display: block;", "newline_before_close_brace", true) + optionHtml("}", "newline_between_rules") + - ""); + "" + + "
"); + + var undoButton = document.querySelector("#help-popup button[role='undo']"); + undoButton.textContent = t(scope.length == 1 ? "undo" : "undoGlobal"); + undoButton.addEventListener("click", function() { + scope.forEach(CodeMirror.commands.undo); + undoButton.disabled = --undoCount == 0; + }); document.querySelector(".beautify-options").addEventListener("change", function(event) { var value = event.target.selectedIndex > 0; @@ -868,6 +877,8 @@ function beautify(event) { prefs.setPref("editor.beautify", options); event.target.parentNode.setAttribute("newline", value.toString()); doBeautify(); + undoCount++; + undoButton.disabled = false; }); function optionHtml(label, optionName, indent) {