codeEditor 代码编辑器
基于 monaco editor, 为你的页面增加代码编辑能力。
由于 monaco editor 对语法处理是通过 web Worker 实现的,所以需要加载处理语法的 Worker, 配置方式参考官方教程.
基本用法
代码高亮
/* Some example CSS */
@import url("something.css");
body {
margin: 0;
padding: 3em 6em;
font-family: tahoma, arial, sans-serif;
color: #000;
}
#navigation a {
font-weight: bold;
text-decoration: none !important;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 1.7em;
}
h1:before, h2:before {
content: "some contents";
}
code {
font-family: courier, monospace;
font-size: 80%;
color: #418A8A;
}CodeEditor 参数
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| v-model | string | '' | 可选,传入编辑器内容 |
| mode | Mode | 'normal' | 可选,编辑器模式 |
| original-text | string | '' | 可选,diff 模式下原始对比文本 |
| theme | Theme | 'light' | 可选,编辑器主题 |
| auto-height | boolean | false | 可选,编辑器高度是否根据内容自适应 |
| refresh-all | boolean | false | 可选, 是否需要刷新全部评论 |
| offset-left | number | -- | 可选, 传入的 domNode 的左偏移量 |
| add-comment-icon | string | '' | 可选, 左侧添加评论图标 |
| expand-comment-icon | string | '' | 可选, 左侧展开评论图标 |
| options | Options | {} | 可选, 编辑器选项,参考 |
| mouse-target-type | monaco.editor.MouseTargetType | [2, 4] | 可选, 鼠标点击返回事件区域 |
| editor-decorations | Decoration[] | [] | 可选, 编辑器的侧边装饰 |
| comments | Comment[] | [] | 可选, 代码检视内容 |
CodeEditor 事件
| 事件 | 回掉参数 | 说明 |
|---|---|---|
| after-editor-init | Function(instance: IStandaloneCodeEditor | IStandaloneDiffEditor) | 初始化完成事件,返回 monaco-editor 实例 |
| click | Function(event: IEditorMouseEvent) | 点击编辑器不同区域返回事件 |
CodeHighlight 参数
暂无
类型定义
Mode
type Mode = 'normal' | 'diff' | 'review';
Theme
type Theme = 'light' | 'dark';
Options
type Options = monaco.IEditorConstructionOptions;
Decoration
interface Decoration {
lineNumber: number;
icon?: string;
customClasses?: string;
glyphClassName?: string;
}
Comment
interface Comment {
lineNumber: number;
isExpanded: boolean;
domNode?: HTMLElement;
heightInPx?: number;
allowEditorOverflow?: boolean;
offsetLedt?: number;
}
IStandaloneCodeEditor
type IStandaloneCodeEditor = monaco.IStandaloneCodeEditor;
IStandaloneDiffEditor
type IStandaloneDiffEditor = monaco.IStandaloneDiffEditor;
