|
6 | 6 | var CodeMirror = require('codemirror/lib/codemirror.js')
|
7 | 7 | var CodeMirrorMetas = require('./metas.js')
|
8 | 8 | require('codemirror/lib/codemirror.css')
|
9 |
| - // var |
| 9 | + require('codemirror/addon/display/fullscreen.css') |
| 10 | + require('codemirror/addon/display/fullscreen.js') |
10 | 11 | export default {
|
11 | 12 | data: function() {
|
12 | 13 | return {
|
13 | 14 | content: ''
|
14 | 15 | }
|
15 | 16 | },
|
16 | 17 | props: {
|
| 18 | + hint: Boolean, |
17 | 19 | code: String,
|
18 | 20 | value: String,
|
19 | 21 | unseenLines: Array,
|
|
34 | 36 | this.options = this.options || {}
|
35 | 37 | var language = this.options.mode || 'text/javascript'
|
36 | 38 | var theme = this.options.theme
|
37 |
| -
|
38 |
| - // string config or object config |
39 |
| - var isString = (typeof language == 'string') |
40 |
| - // console.log(language, typeof language, isString) |
| 39 | + var hint = this.hint || false |
| 40 | + var hints = ['css', 'html', 'javascript', 'sql', 'xml'] |
41 | 41 |
|
42 | 42 | // string config
|
43 |
| - if (isString) { |
| 43 | + if (typeof language == 'string') { |
44 | 44 | try {
|
45 | 45 | language = CodeMirrorMetas.findModeByMIME(language).mode
|
46 | 46 | } catch (e) {
|
47 |
| - throw new Error('CodeMirror language mode: ' + language + ' Configuration error (CodeMirror语言模式配置错误,或者不支持此语言)') |
| 47 | + throw new Error('CodeMirror language mode: ' + language + ' configuration error (CodeMirror语言模式配置错误,或者不支持此语言) See http://codemirror.net/mode/ for more details.') |
48 | 48 | }
|
49 | 49 | }
|
50 | 50 |
|
51 | 51 | // object config
|
52 |
| - if (!isString) { |
| 52 | + if (typeof language == 'object') { |
53 | 53 | try {
|
54 | 54 | language = CodeMirrorMetas.findModeByName(language.name).mode
|
55 | 55 | } catch (e) {
|
56 |
| - throw new Error('CodeMirror language mode: ' + language.name + ' Configuration error (CodeMirror语言模式配置错误,或者不支持此语言)') |
| 56 | + throw new Error('CodeMirror language mode: ' + language.name + ' configuration error (CodeMirror语言模式配置错误,或者不支持此语言) See http://codemirror.net/mode/ for more details.') |
57 | 57 | }
|
58 | 58 | }
|
59 | 59 |
|
60 |
| - // console.log(language) |
61 |
| - // require editor language and theme config |
| 60 | + // require hint config |
| 61 | + if (hint) { |
| 62 | + require('codemirror/addon/hint/show-hint.js') |
| 63 | + require('codemirror/addon/hint/show-hint.css') |
| 64 | + var isAnyword = hints.indexOf(language) == -1 |
| 65 | + require('codemirror/addon/hint/' + (isAnyword ? 'anyword' : language) + '-hint.js') |
| 66 | + } |
| 67 | +
|
| 68 | + // require active-line.js |
| 69 | + if (this.options.styleActiveLine) require('codemirror/addon/selection/active-line.js') |
| 70 | +
|
| 71 | + // require closebrackets.js |
| 72 | + if (this.options.autoCloseBrackets) require('codemirror/addon/edit/closebrackets.js') |
| 73 | +
|
| 74 | + // require closetag.js |
| 75 | + if (this.options.autoCloseTags) require('codemirror/addon/edit/closetag.js') |
| 76 | +
|
| 77 | + // require styleSelectedText.js |
| 78 | + if (this.options.styleSelectedText) { |
| 79 | + require('codemirror/addon/selection/mark-selection.js') |
| 80 | + require('codemirror/addon/search/searchcursor.js') |
| 81 | + } |
| 82 | +
|
| 83 | + // highlightSelectionMatches |
| 84 | + if (this.options.highlightSelectionMatches) { |
| 85 | + require('codemirror/addon/scroll/annotatescrollbar.js') |
| 86 | + require('codemirror/addon/search/matchesonscrollbar.js') |
| 87 | + require('codemirror/addon/search/searchcursor.js') |
| 88 | + require('codemirror/addon/search/match-highlighter.js') |
| 89 | + } |
| 90 | +
|
| 91 | + // require emacs |
| 92 | + if (!!this.options.keyMap && ['emacs', 'sublime', 'vim'].indexOf(this.options.keyMap) > -1) { |
| 93 | + require('codemirror/mode/clike/clike.js') |
| 94 | + require('codemirror/addon/edit/matchbrackets.js') |
| 95 | + require('codemirror/addon/comment/comment.js') |
| 96 | + require('codemirror/addon/dialog/dialog.js') |
| 97 | + require('codemirror/addon/dialog/dialog.css') |
| 98 | + require('codemirror/addon/search/searchcursor.js') |
| 99 | + require('codemirror/addon/search/search.js') |
| 100 | + // console.log(this.options.keyMap) |
| 101 | + require('codemirror/keymap/'+ this.options.keyMap +'.js') |
| 102 | + } |
| 103 | +
|
| 104 | + // require fold js |
| 105 | + if (this.options.foldGutter) { |
| 106 | + require('codemirror/addon/fold/foldgutter.css') |
| 107 | + require('codemirror/addon/fold/brace-fold.js') |
| 108 | + require('codemirror/addon/fold/comment-fold.js') |
| 109 | + require('codemirror/addon/fold/foldcode.js') |
| 110 | + require('codemirror/addon/fold/foldgutter.js') |
| 111 | + require('codemirror/addon/fold/indent-fold.js') |
| 112 | + require('codemirror/addon/fold/markdown-fold.js') |
| 113 | + require('codemirror/addon/fold/xml-fold.js') |
| 114 | + } |
| 115 | +
|
| 116 | + // require language mode config |
62 | 117 | require('codemirror/mode/' + language + '/' + language + '.js')
|
63 | 118 |
|
| 119 | + // require theme config |
64 | 120 | if (!!theme && theme == 'solarized light') theme = 'solarized'
|
65 | 121 | if (!!theme && theme != 'default') require('codemirror/theme/' + theme + '.css')
|
66 | 122 | },
|
|
124 | 180 | </script>
|
125 | 181 |
|
126 | 182 | <style>
|
127 |
| - .CodeMirror, |
128 |
| - .CodeMirror pre { |
129 |
| - font-family: Menlo, Monaco, Consolas, "Courier New", monospace!important; |
130 |
| - padding: 0 20px !important; /* Horizontal padding of content */ |
| 183 | + .CodeMirror-code { |
| 184 | + line-height: 1.6em; |
| 185 | + font-family: Menlo, Monaco, Consolas, "Courier New", monospace; |
131 | 186 | }
|
132 | 187 | </style>
|
0 commit comments