12
12
@input =" changeEditorContent"
13
13
></div >
14
14
<!-- 功能 -->
15
- <section class =" bottom-editor-tools" :class =" windowBlur ? 'window-blur-hide' : '' " >
15
+ <section class =" bottom-editor-tools" :class =" bottomClass " >
16
16
<template v-for =" item in bottomIcons " :key =" item .name " >
17
17
<button class =" icon" :title =" item.title" @click =" editorIconHandle($event, item.name)" >
18
18
<i class =" iconfont" :class =" item.icon" ></i >
22
22
</template >
23
23
24
24
<script lang="ts">
25
- import { defineComponent , nextTick , onMounted , ref , Ref , watch } from ' vue' ;
25
+ import { computed , defineComponent , nextTick , onMounted , ref , Ref , watch } from ' vue' ;
26
26
import { debounce } from ' @/utils' ;
27
27
import { editorIcons } from ' @/config' ;
28
28
import { notesState } from ' @/store/notes.state' ;
@@ -35,6 +35,10 @@ export default defineComponent({
35
35
windowBlur: {
36
36
type: Boolean ,
37
37
default: true
38
+ },
39
+ windowLock: {
40
+ type: Boolean ,
41
+ default: true
38
42
}
39
43
},
40
44
emits: [' on-input' , ' update:value' ],
@@ -56,12 +60,24 @@ export default defineComponent({
56
60
}
57
61
}
58
62
);
63
+ const bottomClass = computed (() => {
64
+ const classArr = [];
65
+ if (props .windowBlur ) {
66
+ classArr .push (' window-blur-hide' );
67
+ } else {
68
+ if (props .windowLock ) {
69
+ // 当锁上的时候,编辑器任然处于失去焦点的情况
70
+ // 需要解锁才能正常
71
+ classArr .push (' window-blur-hide' );
72
+ }
73
+ }
74
+ return classArr ;
75
+ });
59
76
60
77
// 第一次进入事件
61
78
const firstHandle = () => {
62
79
nextTick (() => {
63
80
focus ();
64
- console .dir (editor .value );
65
81
editor .value ?.scrollTo (0 , editor .value .scrollHeight );
66
82
firstIn .value = false ;
67
83
});
@@ -88,11 +104,40 @@ export default defineComponent({
88
104
const changeEditorContent = debounce ((e : InputEvent ) => {
89
105
const editorHtml = (e .target as Element ).innerHTML ;
90
106
emit (' on-input' , editorHtml );
91
- }, notesState .syncDelay );
107
+ }, notesState .value . syncDelay );
92
108
93
109
const paste = (e : ClipboardEvent ) => {
94
110
const pasteText = e .clipboardData ?.getData (' text/plain' );
95
- document .execCommand (' insertText' , false , pasteText );
111
+ const setText = (text ? : string ) => {
112
+ document .execCommand (' insertText' , false , text );
113
+ };
114
+ const interceptPoint = 100000 ;
115
+ // 做超长文本处理
116
+ // TODO
117
+ const len = pasteText ! .length ;
118
+ if (! len ) return ;
119
+ if (len < interceptPoint ) {
120
+ setText (pasteText );
121
+ } else {
122
+ const count = Math .ceil (len / interceptPoint );
123
+ let control = 0 ;
124
+ let interval: any = setInterval (() => {
125
+ let text = ' ' ;
126
+ if (control === 0 ) {
127
+ text = pasteText ! .substring (0 , (control + 1 ) * interceptPoint );
128
+ } else if (control !== 0 && control !== count ) {
129
+ text = pasteText ! .substring (control * interceptPoint , (control + 1 ) * interceptPoint );
130
+ }
131
+ setText (text );
132
+ if (control >= count ) {
133
+ text = ' ' ;
134
+ clearInterval (interval );
135
+ interval = null ;
136
+ editor .value ?.scrollTo (0 , editor .value .scrollHeight );
137
+ }
138
+ control ++ ;
139
+ }, 100 );
140
+ }
96
141
};
97
142
98
143
return {
@@ -101,7 +146,8 @@ export default defineComponent({
101
146
bottomIcons ,
102
147
changeEditorContent ,
103
148
paste ,
104
- editorContent
149
+ editorContent ,
150
+ bottomClass
105
151
};
106
152
}
107
153
});
0 commit comments