文本编辑器添加搜索功能

This commit is contained in:
jmal 2020-05-25 15:30:30 +08:00
parent 5fef36179c
commit 3bddeebab4
4 changed files with 29 additions and 47 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
push.sh
update.sh
dist.tar
.DS_Store .DS_Store
node_modules/ node_modules/
dist/ dist/

View File

@ -1,6 +1,6 @@
{ {
"name": "jmal-cloud-view", "name": "jmal-cloud-view",
"version": "1.0.0", "version": "1.0.1",
"description": "jmal cloud", "description": "jmal cloud",
"author": "Jmal <zhushilun084@163.com>", "author": "Jmal <zhushilun084@163.com>",
"license": "MIT", "license": "MIT",

View File

@ -80,12 +80,15 @@
require('codemirror/addon/hint/xml-hint.js') require('codemirror/addon/hint/xml-hint.js')
// Crtl-F 搜索 // Crtl-F 搜索
import 'codemirror/addon/dialog/dialog';
import 'codemirror/addon/scroll/annotatescrollbar'; import 'codemirror/addon/scroll/annotatescrollbar.js'
import 'codemirror/addon/search/matchesonscrollbar'; import 'codemirror/addon/search/matchesonscrollbar.js'
import 'codemirror/addon/search/jump-to-line'; import 'codemirror/addon/search/match-highlighter.js'
import 'codemirror/addon/search/search'; import 'codemirror/addon/search/jump-to-line.js'
import 'codemirror/addon/search/searchcursor'; import 'codemirror/addon/dialog/dialog.js'
import 'codemirror/addon/dialog/dialog.css'
import 'codemirror/addon/search/searchcursor.js'
import 'codemirror/addon/search/search.js'
let CodeMirror = require('codemirror/lib/codemirror.js') let CodeMirror = require('codemirror/lib/codemirror.js')
require('codemirror/lib/codemirror.css') require('codemirror/lib/codemirror.css')
@ -102,7 +105,11 @@
return { return {
mode: 'text/javascript', mode: 'text/javascript',
lineNumbers: true, lineNumbers: true,
lineWrapping: true lineWrapping: true,
// foldGutter: true, // 启用行槽中的代码折叠
// // 在行槽中添加行号显示器、折叠器、语法检测器
// gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"],
// lint: true,
} }
} }
}, },
@ -113,26 +120,6 @@
nowValue: '' nowValue: ''
} }
}, },
// ready: function () {
// let that = this
// this.editor = CodeMirror.fromTextArea(this.$el.querySelector('textarea'), this.options)
// this.editor.setValue(this.value)
// this.editor.on('change', function(cm) {
// console.log('change')
// if (that.skipNextChangeEvent) {
// that.skipNextChangeEvent = false
// return
// }
// that.nowValue = cm.getValue()
// if (!!that.$emit) {
// that.$emit('change', cm.getValue())
// }
// })
// this.editor.on("cursorActivity", () => {
// console.log('cursorActivity')
// this.editor.showHint();
// });
// },
beforeMount(){ beforeMount(){
this.onKeyDown = this.onKeyDown.bind(this); this.onKeyDown = this.onKeyDown.bind(this);
document.addEventListener('keydown', this.onKeyDown); document.addEventListener('keydown', this.onKeyDown);
@ -153,13 +140,10 @@
} }
}) })
this.editor.on("cursorActivity", () => { console.log(this.editor)
console.log('cursorActivity')
// this.editor.showHint();
});
this.$nextTick(()=>{ this.$nextTick(()=>{
this.editor.clearHistory(); this.editor.clearHistory()
}) })
}, },
watch: { watch: {
@ -173,7 +157,7 @@
this.editor.scrollTo(0, 0) this.editor.scrollTo(0, 0)
// this.editor.scrollTo(scrollInfo.left, scrollInfo.top) // this.editor.scrollTo(scrollInfo.left, scrollInfo.top)
} }
this.editor.clearHistory(); this.editor.clearHistory()
}, },
'options': function (newOptions, oldVal) { 'options': function (newOptions, oldVal) {
if (typeof newOptions === 'object') { if (typeof newOptions === 'object') {
@ -201,11 +185,6 @@
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} }
const isF = key === 'f' || code === 'KeyF' || keyCode === 70;
if (isF && this.editor) {
this.editor.execCommand('find');
event.preventDefault();
}
}, },
}, },
beforeDestroy: function () { beforeDestroy: function () {

View File

@ -58,25 +58,25 @@
computed: { computed: {
options: function () { options: function () {
return { return {
mode: this.codeMode,//代码高亮 mode: this.codeMode,// 代码高亮
smartIndent: true, // 智能缩进 smartIndent: true, // 智能缩进
indentUnit: 4, // 智能缩进单位为4个空格长度 indentUnit: 4, // 智能缩进单位为4个空格长度
indentWithTabs: true, // 使用制表符进行智能缩进 indentWithTabs: true, // 使用制表符进行智能缩进
styleActiveLine: true, // 显示选中行的样式 styleActiveLine: true, // 显示选中行的样式
lineNumbers: true, //显示行号 lineNumbers: true, //显示行号
lineWrapping: this.lineWrapping,//代码折叠 lineWrapping: this.lineWrapping, //代码换行显示
foldGutter: true, // 启用行槽中的代码折叠 // foldGutter: true, // 启用行槽中的代码折叠
// 在行槽中添加行号显示器、折叠器、语法检测器 // // 在行槽中添加行号显示器、折叠器、语法检测器
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"], // gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"],
lint: true,
readOnly: this.readOnly, readOnly: this.readOnly,
theme: 'darcula', theme: 'darcula',
// theme: 'default', // theme: 'default',
fullScreen: false, // 全屏 fullScreen: false, // 全屏
matchBrackets: true, //括号匹配 matchBrackets: true, // 括号匹配
hintOptions: { hintOptions: {
completeSingle: false completeSingle: false
}, },
lint: true,
extraKeys: {'ctrl-space': 'autocomplete'}, //智能提示 extraKeys: {'ctrl-space': 'autocomplete'}, //智能提示
} }
} }
@ -91,7 +91,7 @@
codeMode: 'javascript', codeMode: 'javascript',
previewMode: true, previewMode: true,
lineWrapping: false, lineWrapping: false,
readOnly: this.$store.state.user.token ? false : true, readOnly: !this.$store.state.user.token,
isShowUpdateBtn: false, isShowUpdateBtn: false,
updating: false, updating: false,
loading: {}, loading: {},