@@ -14,71 +14,74 @@ import {codemirror} from 'vue-codemirror-lite'
1414import ' codemirror/mode/markdown/markdown.js'
1515
1616export default {
17- name: ' input-area' ,
18- props: {
19- value: {
20- type: String
17+ name: ' input-area' ,
18+ props: {
19+ value: {
20+ type: String
21+ },
22+ editorOption: {
23+ type: Object
24+ },
25+ height: {
26+ type: String ,
27+ default: ' 400px'
28+ },
29+ insertCode: {
30+ default: null
31+ }
2132 },
22- editorOption: {
23- type: Object
33+ computed: {
34+ editor () {
35+ return this .$refs .editor .editor
36+ }
2437 },
25- height: {
26- type: String ,
27- default: ' 400px'
28- },
29- insertCode: {
30- default: null
31- }
32- },
33- computed: {
34- editor () {
35- return this .$refs .editor .editor
36- }
37- },
38- watch: {
39- insertCode : function (insert ) {
40- if (insert === null ) {
41- return
42- }
38+ watch: {
39+ insertCode (insert ) {
40+ if (insert === null ) {
41+ return
42+ }
4343
44- if (typeof insert === ' function' ) { insert = insert () }
44+ if (typeof insert === ' function' ) { insert = insert () }
4545
46- if (! Array .isArray (insert)) {
47- insert = [insert, ' ' ]
48- }
46+ if (! Array .isArray (insert)) {
47+ insert = [insert, ' ' ]
48+ }
4949
50- let cursor = this .editor .getCursor ()
51- let selection = this .editor .getSelection ()
50+ let cursor = this .editor .getCursor ()
51+ let selection = this .editor .getSelection ()
5252
53- this .editor .replaceSelection (insert[0 ] + selection + insert[1 ])
53+ this .editor .replaceSelection (insert[0 ] + selection + insert[1 ])
5454
55- if (selection === ' ' ) {
56- this .editor .setCursor (cursor .line , cursor .ch + 2 )
57- }
55+ if (selection === ' ' ) {
56+ this .editor .setCursor (cursor .line , cursor .ch + 2 )
57+ }
5858
59- this .$emit (' finish' )
59+ this .$emit (' finish' )
60+ },
61+ height (newHeight ) {
62+ this .editor .setSize (' 100%' , newHeight)
63+ },
64+ value (newValue ) {
65+ this .code = newValue
66+ }
6067 },
61- height : function (newHeight ) {
62- this .editor .setSize (' 100%' , newHeight)
63- }
64- },
65- data : function () {
66- return {
67- code: ' '
68- }
69- },
70- components: {
71- codemirror
72- },
73- mounted : function () {
74- this .code = this .value
75- this .editor .setSize (' 100%' , this .height )
76- this .editor .focus ()
77- },
78- methods: {
79- updateCode (code ) {
80- this .$emit (' input' , code)
68+ data : function () {
69+ return {
70+ code: ' '
71+ }
72+ },
73+ components: {
74+ codemirror
75+ },
76+ mounted : function () {
77+ this .code = this .value
78+ this .editor .setSize (' 100%' , this .height )
79+ this .editor .focus ()
80+ },
81+ methods: {
82+ updateCode (code ) {
83+ this .$emit (' input' , code)
84+ }
8185 }
82- }
8386}
8487 </script >
0 commit comments