Skip to content

Commit 0d25224

Browse files
committed
The editor is now refreshed when in a newly expanded builder block. Fixes #77
1 parent 58a3435 commit 0d25224

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/field/Markdown.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@ export default {
1313
blank: Boolean,
1414
invisibles: Boolean,
1515
kirbytags: Array,
16+
},
17+
// below, code to refresh input within a newly expanded builder block
18+
computed: {
19+
builderBlock() {
20+
return this.getParentComponent('builder-block')
21+
},
22+
builderExpanded() {
23+
return this.builderBlock && this.builderBlock.expanded
24+
}
25+
},
26+
watch: {
27+
builderExpanded(newVal, oldVal) {
28+
if (newVal === true) {
29+
this.$root.$emit('md-refresh' + this._uid)
30+
}
31+
},
32+
},
33+
methods: {
34+
getParentComponent(componentName) {
35+
let component = null
36+
let parent = this.$parent
37+
while (parent && !component) {
38+
if (parent.$options._componentTag === componentName) {
39+
component = parent
40+
}
41+
parent = parent.$parent
42+
}
43+
return component
44+
},
1645
}
1746
};
1847
</script>

src/components/input/MarkdownInput.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export default {
4646
skipNextChangeEvent: false,
4747
currentDialog: null,
4848
currentTokenType: null,
49-
id: '',
5049
}
5150
},
5251
props: {
52+
id: Number,
5353
autofocus: Boolean,
5454
modals: Boolean,
5555
blank: Boolean,
@@ -90,15 +90,17 @@ export default {
9090
return this.$store.state.languages.current
9191
}
9292
},
93-
created() {
94-
this.id = this._uid
95-
},
9693
mounted() {
9794
this.editor = CodeMirror.fromTextArea(this.$refs.input, this.options);
9895
this.editor.setValue(this.value || '');
9996
10097
// force refresh after setValue, else some text might not be rendered before the editor is clicked
101-
this.$nextTick(() => this.editor.refresh())
98+
this.refresh()
99+
100+
// event triggered from parent
101+
this.$root.$on('md-refresh' + this.id, () => {
102+
this.refresh()
103+
})
102104
103105
// Custom autofocus: place the cursor at the end of current value
104106
if(this.autofocus) {
@@ -180,10 +182,13 @@ export default {
180182
this.editor.scrollTo(scrollInfo.left, scrollInfo.top)
181183
}
182184
// force refresh
183-
this.$nextTick(() => this.editor.refresh())
185+
this.refresh()
184186
},
185187
},
186188
methods: {
189+
refresh() {
190+
this.$nextTick(() => this.editor.refresh())
191+
},
187192
/**
188193
* Close any open dialog and bring focus back to the editor
189194
*/

0 commit comments

Comments
 (0)