restore editor window size when reopened via Ctrl-Shift-T
This commit is contained in:
parent
0d6f7e0a4b
commit
021f50015b
16
edit.html
16
edit.html
|
@ -1,6 +1,14 @@
|
||||||
<html id="stylus">
|
<html id="stylus">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||||
|
|
||||||
|
<script src="dom.js"></script>
|
||||||
|
<script src="messaging.js"></script>
|
||||||
|
<script src="prefs.js"></script>
|
||||||
|
<script src="localization.js"></script>
|
||||||
|
<script src="apply.js"></script>
|
||||||
|
<script src="edit.js"></script>
|
||||||
|
|
||||||
<script src="codemirror/lib/codemirror.js"></script>
|
<script src="codemirror/lib/codemirror.js"></script>
|
||||||
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
||||||
<script src="codemirror/mode/css/css.js"></script>
|
<script src="codemirror/mode/css/css.js"></script>
|
||||||
|
@ -644,14 +652,8 @@
|
||||||
<template data-id="regexpTestPartial">
|
<template data-id="regexpTestPartial">
|
||||||
<a target="_blank" href="https://github.com/stylish-userstyles/stylish/wiki/Applying-styles-to-specific-sites#advanced-matching-with-regular-expressions"><svg class="svg-icon info"><use xlink:href="#svg-icon-help"/></svg></a>
|
<a target="_blank" href="https://github.com/stylish-userstyles/stylish/wiki/Applying-styles-to-specific-sites#advanced-matching-with-regular-expressions"><svg class="svg-icon info"><use xlink:href="#svg-icon-help"/></svg></a>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="dom.js"></script>
|
|
||||||
<script src="messaging.js"></script>
|
|
||||||
<script src="prefs.js"></script>
|
|
||||||
<script src="localization.js"></script>
|
|
||||||
<script src="apply.js"></script>
|
|
||||||
<script src="edit.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body id="stylus-edit">
|
<body id="stylus-edit">
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<h1 id="heading"> </h1> <!-- nbsp allocates the actual height which prevents page shift -->
|
<h1 id="heading"> </h1> <!-- nbsp allocates the actual height which prevents page shift -->
|
||||||
|
|
23
edit.js
23
edit.js
|
@ -37,6 +37,16 @@ Array.prototype.rotate = function(amount) { // negative amount == rotate left
|
||||||
|
|
||||||
Object.defineProperty(Array.prototype, "last", {get: function() { return this[this.length - 1]; }});
|
Object.defineProperty(Array.prototype, "last", {get: function() { return this[this.length - 1]; }});
|
||||||
|
|
||||||
|
// preload the theme so that CodeMirror can calculate its metrics in DOMContentLoaded->setupLivePrefs()
|
||||||
|
new MutationObserver((mutations, observer) => {
|
||||||
|
const themeElement = document.getElementById("cm-theme");
|
||||||
|
if (themeElement) {
|
||||||
|
themeElement.href = prefs.get("editor.theme") == "default" ? ""
|
||||||
|
: "codemirror/theme/" + prefs.get("editor.theme") + ".css";
|
||||||
|
observer.disconnect();
|
||||||
|
}
|
||||||
|
}).observe(document, {subtree: true, childList: true});
|
||||||
|
|
||||||
// reroute handling to nearest editor when keypress resolves to one of these commands
|
// reroute handling to nearest editor when keypress resolves to one of these commands
|
||||||
var hotkeyRerouter = {
|
var hotkeyRerouter = {
|
||||||
commands: {
|
commands: {
|
||||||
|
@ -239,12 +249,7 @@ function initCodeMirror() {
|
||||||
return this.display.wrapper.parentNode;
|
return this.display.wrapper.parentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// preload the theme so that CodeMirror can calculate its metrics in DOMContentLoaded->setupLivePrefs()
|
|
||||||
var theme = prefs.get("editor.theme");
|
|
||||||
document.getElementById("cm-theme").href = theme == "default" ? "" : "codemirror/theme/" + theme + ".css";
|
|
||||||
|
|
||||||
// initialize global editor controls
|
// initialize global editor controls
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
|
||||||
function optionsHtmlFromArray(options) {
|
function optionsHtmlFromArray(options) {
|
||||||
return options.map(function(opt) { return "<option>" + opt + "</option>"; }).join("");
|
return options.map(function(opt) { return "<option>" + opt + "</option>"; }).join("");
|
||||||
}
|
}
|
||||||
|
@ -253,6 +258,7 @@ function initCodeMirror() {
|
||||||
themeControl.innerHTML = optionsHtmlFromArray(BG.codeMirrorThemes);
|
themeControl.innerHTML = optionsHtmlFromArray(BG.codeMirrorThemes);
|
||||||
} else {
|
} else {
|
||||||
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
|
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
|
||||||
|
const theme = prefs.get("editor.theme");
|
||||||
themeControl.innerHTML = optionsHtmlFromArray([theme == "default" ? t("defaultTheme") : theme]);
|
themeControl.innerHTML = optionsHtmlFromArray([theme == "default" ? t("defaultTheme") : theme]);
|
||||||
BG.getCodeMirrorThemes().then(themes => {
|
BG.getCodeMirrorThemes().then(themes => {
|
||||||
BG.codeMirrorThemes = themes;
|
BG.codeMirrorThemes = themes;
|
||||||
|
@ -266,11 +272,9 @@ function initCodeMirror() {
|
||||||
document.querySelectorAll("#options *[data-option][id^='editor.']")
|
document.querySelectorAll("#options *[data-option][id^='editor.']")
|
||||||
.map(function(option) { return option.id })
|
.map(function(option) { return option.id })
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
hotkeyRerouter.setState(true);
|
hotkeyRerouter.setState(true);
|
||||||
}
|
}
|
||||||
initCodeMirror();
|
|
||||||
|
|
||||||
function acmeEventListener(event) {
|
function acmeEventListener(event) {
|
||||||
var el = event.target;
|
var el = event.target;
|
||||||
|
@ -416,6 +420,10 @@ document.addEventListener("wheel", function(event) {
|
||||||
chrome.tabs.query({currentWindow: true}, function(tabs) {
|
chrome.tabs.query({currentWindow: true}, function(tabs) {
|
||||||
var windowId = tabs[0].windowId;
|
var windowId = tabs[0].windowId;
|
||||||
if (prefs.get("openEditInWindow")) {
|
if (prefs.get("openEditInWindow")) {
|
||||||
|
if (sessionStorage.saveSizeOnClose && 'left' in prefs.get('windowPosition', {})) {
|
||||||
|
// window was reopened via Ctrl-Shift-T etc.
|
||||||
|
chrome.windows.update(windowId, prefs.get('windowPosition'));
|
||||||
|
}
|
||||||
if (tabs.length == 1 && window.history.length == 1) {
|
if (tabs.length == 1 && window.history.length == 1) {
|
||||||
chrome.windows.getAll(function(windows) {
|
chrome.windows.getAll(function(windows) {
|
||||||
if (windows.length > 1) {
|
if (windows.length > 1) {
|
||||||
|
@ -1111,6 +1119,7 @@ function beautify(event) {
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
document.addEventListener("DOMContentLoaded", init);
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
initCodeMirror();
|
||||||
var params = getParams();
|
var params = getParams();
|
||||||
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
|
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
|
||||||
// This is an add
|
// This is an add
|
||||||
|
|
Loading…
Reference in New Issue
Block a user