0.0.1 • Published 3 years ago

tq-ace-editor v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

安装

npm install tq-ace-editor
// or
yarn tq-ace-editor

使用

局部引用

<template>
  <Editor />
</template>
<script>
  import Editor from 'tq-ace-editor'
  export default {
    components: { Editor }
  }
</script>

全局引入

// main.js
import Editor from 'tq-ace-editor'
Vue.component('Editor',Editor)

示例

<template>
  <Editor
    height="80vh"
    width="100%"
    ref="editor"
    v-model="content"
    :options="aceOption"
    lang="sh"
    @init="editorInit"
    theme="tomorrow_night_bright"/>
</template>
<script>
  import Editor from 'tq-ace-editor'
  export default {
    data() {
      return {
        content: '',
        aceOption: {
          enableBasicAutocompletion: true,
          enableSnippets: true,
          enableLiveAutocompletion: true,
          tabSize: 6,
          fontSize: 14
        }
      }
    },
    components: { Editor },
    methods: {
      editorInit() {
        require('brace/ext/language_tools')
        require('brace/mode/sh')
        require('brace/theme/tomorrow_night_bright')
        require('brace/snippets/sh')
      }
    }
  }
</script>

hook

名称说明类型默认值
init编辑器初始化钩子,当初始化完成后触发fn-

属性

名称说明类型默认值
value编辑器内容String-
lang编辑器语言Stringtext
theme编辑器主题名Stringchrome
height编辑器高度String100%
width编辑器宽度String100%
options编辑器配置项Object{}

options 选项

editor选项

选项名值类型默认值可选值备注
selectionStyleStringtextline/text选中样式
highlightActiveLineBooleantrue-高亮当前行
highlightSelectedWordBooleantrue-高亮选中文本
readOnlyBooleanfalse-是否只读
cursorStyleStringaceace/slim/smooth/wide光标样式
mergeUndoDeltasString/Booleanfalsealways合并撤销
behavioursEnabledBooleantrue-启用行为
wrapBehavioursEnabledBooleantrue-启用换行
autoScrollEditorIntoViewBooleanfalse-启用滚动
copyWithEmptySelectionBooleantrue-复制空格
useSoftTabsBooleanfalse-使用软标签
navigateWithinSoftTabsBooleanfalse-软标签跳转
enableMultiselectBooleanfalse-选中多处

renderer选项

选项名值类型默认值可选值备注
hScrollBarAlwaysVisibleBooleanfalse-纵向滚动条始终可见
vScrollBarAlwaysVisibleBooleanfalse-横向滚动条始终可见
highlightGutterLineBooleantrue-高亮边线
animatedScrollBooleanfalse-滚动动画
showInvisiblesBooleanfalse-显示不可见字符
showPrintMarginBoolean true-显示打印边距
printMarginColumnNumber80-设置页边距
printMarginBoolean/Numberfalse-显示并设置页边距
fadeFoldWidgetsBooleanfalse-淡入折叠部件
showFoldWidgetsBooleantrue-显示折叠部件
showLineNumbersBooleantrue-显示行号
showGutterBooleantrue-显示行号区域
displayIndentGuidesBooleantrue-显示参考线
fontSizeNumber/Stringinherit-设置字号
fontFamilyStringinherit-设置字体
maxLinesNumber--至多行数
minLinesNumber--至少行数
scrollPastEndBoolean/Number0-滚动位置
fixedWidthGutterBooleanfalse-固定行号区域宽度
themeString--主题引用路径,例如"ace/theme/textmate"

mouseHandler选项

选项名值类型默认值可选值备注
scrollSpeedNumber--滚动速度
dragDelayNumber--拖拽延时
dragEnabledBooleantrue-是否启用拖动
focusTimoutNumber--聚焦超时
tooltipFollowsMouseBooleanfalse-鼠标提示

session选项

选项名值类型默认值可选值备注
firstLineNumberNumber1-起始行号
overwriteBoolean--重做
newLineModeStringautoauto/unix/windows新开行模式
useWorkerBoolean--使用辅助对象
useSoftTabsBoolean--使用软标签
tabSizeNumber--标签大小
wrapBoolean--换行
foldStyleString-markbegin/markbeginend/manual折叠样式
modeString--代码匹配模式,例如“ace/mode/text"

扩展选项

选项名值类型默认值可选值备注
enableBasicAutocompletionBoolean--启用基本自动完成
enableLiveAutocompletionBoolean--启用实时自动完成
enableSnippetsBoolean--启用代码段
enableEmmetBoolean--启用Emmet
useElasticTabstopsBoolean--使用弹性制表位

主题

使用主题的时候记得一定要先引主题再使用!require('brace/theme/主题名')

语言

使用主题的时候记得一定要先引主题再使用!require('brace/mode/语言名')

其他

要使用语言或者主题时,记得都要require一下相关的文件才能使用!记得切换npm仓库为私有仓库不然无法下载这个包!