Change ace-editor theme by PW theme changing.

This commit is contained in:
Hossein Nedaee
2019-11-11 20:44:24 +03:30
parent 716434d59e
commit 179010ddbf
4 changed files with 60 additions and 42 deletions

View File

@@ -3,6 +3,8 @@
</template> </template>
<script> <script>
const DEFAULT_THEME = 'dracula';
import ace from 'ace-builds'; import ace from 'ace-builds';
import "ace-builds/webpack-resolver"; import "ace-builds/webpack-resolver";
@@ -15,27 +17,15 @@ export default {
}, },
theme: { theme: {
type: String, type: String,
default: 'dracula' required: false
}, },
lang: { lang: {
type: String, type: String,
default: 'json' default: 'json',
}, },
rows: { options: {
type: Number, type: Object,
default: 16 default: {}
},
fontSize: {
type: String,
default: '16px'
},
placeholder: {
type: String,
default: ''
},
checkSyntax: {
type: Boolean,
default: false
} }
}, },
@@ -47,33 +37,45 @@ export default {
}, },
watch: { watch: {
value(val) { value(value) {
if(val !== this.cacheValue) { if(value !== this.cacheValue) {
this.editor.session.setValue(val,1); this.editor.session.setValue(value,1);
this.cacheValue = val; this.cacheValue = value;
} }
},
theme() {
this.editor.setTheme('ace/theme/' + this.defineTheme())
},
lang(value) {
this.editor.getSession().setMode('ace/mode/' + value);
},
options(value) {
this.editor.setOptions(value);
} }
}, },
mounted() { mounted() {
const editor = ace.edit(this.$refs.editor, { const editor = ace.edit(this.$refs.editor, {
theme: 'ace/theme/'+ this.theme, theme: 'ace/theme/'+ this.defineTheme(),
mode: "ace/mode/" + this.lang, mode: "ace/mode/" + this.lang,
maxLines: this.rows, ...this.options
minLines: this.rows, })
fontSize: this.fontSize,
autoScrollEditorIntoView: true,
readOnly: true,
showPrintMargin: false,
})
editor.setValue(this.value); editor.setValue(this.value);
this.cacheValue = this.value;
editor.session.setUseWorker(this.checkSyntax)
this.editor = editor; this.editor = editor;
this.cacheValue = this.value;
},
methods: {
defineTheme() {
if(this.theme) {
return this.theme;
} else {
return this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME
}
}
}, },
beforeDestroy() { beforeDestroy() {

View File

@@ -570,11 +570,17 @@
<div id="response-details-wrapper"> <div id="response-details-wrapper">
<ResponseBody <ResponseBody
:value="responseBodyText" :value="responseBodyText"
theme="dracula"
lang="json" lang="json"
:rows="16" :options="{
fontSize="16px" maxLines: '16',
placeholder="(waiting to send request)" /> minLines: '16',
fontSize: '16px',
autoScrollEditorIntoView: true,
readOnly: true,
showPrintMargin: false,
useWorker: false
}"
/>
<iframe <iframe
:class="{hidden: !previewEnabled}" :class="{hidden: !previewEnabled}"
class="covers-response" class="covers-response"

View File

@@ -7,7 +7,7 @@
<div class="backgrounds"> <div class="backgrounds">
<span <span
:key="theme.class" :key="theme.class"
@click="applyTheme(theme.class, theme.color)" @click="applyTheme(theme)"
v-for="theme in themes" v-for="theme in themes"
> >
<swatch <swatch
@@ -128,24 +128,28 @@ export default {
{ {
color: "#252628", color: "#252628",
name: "Kinda Dark", name: "Kinda Dark",
class: "" class: "",
aceEditor: "dracula"
}, },
{ {
color: "#ffffff", color: "#ffffff",
name: "Clearly White", name: "Clearly White",
vibrant: true, vibrant: true,
class: "light" class: "light",
aceEditor: "xcode"
}, },
{ {
color: "#000000", color: "#000000",
name: "Just Black", name: "Just Black",
class: "black" class: "black",
aceEditor: "tomorrow_night_blue"
}, },
{ {
color: "var(--bg-color)", color: "var(--bg-color)",
name: "Auto (system)", name: "Auto (system)",
vibrant: window.matchMedia("(prefers-color-scheme: light)").matches, vibrant: window.matchMedia("(prefers-color-scheme: light)").matches,
class: "auto" class: "auto",
aceEditor: window.matchMedia("(prefers-color-scheme: light)").matches ? 'xcode' : 'dracula'
} }
], ],
// You can define a new color here! It will simply store the color value. // You can define a new color here! It will simply store the color value.
@@ -220,8 +224,9 @@ export default {
}, },
methods: { methods: {
applyTheme(name, color) { applyTheme({class:name, color, aceEditor}) {
this.applySetting("THEME_CLASS", name); this.applySetting("THEME_CLASS", name);
this.applySetting("THEME_ACE_EDITOR", aceEditor);
document document
.querySelector("meta[name=theme-color]") .querySelector("meta[name=theme-color]")
.setAttribute("content", color); .setAttribute("content", color);

View File

@@ -26,6 +26,11 @@ export const SETTINGS_KEYS = [
*/ */
"THEME_COLOR_VIBRANT", "THEME_COLOR_VIBRANT",
/**
* The Ace editor theme
*/
"THEME_ACE_EDITOR",
/** /**
* Normally, section frames are multicolored in the UI * Normally, section frames are multicolored in the UI
* to emphasise the different sections. * to emphasise the different sections.