1212 @input =" changeEditorContent"
1313 ></div >
1414 <!-- 功能 -->
15- <section class =" bottom-editor-tools" :class =" windowBlur ? 'window-blur-hide' : '' " >
15+ <section class =" bottom-editor-tools" :class =" bottomClass " >
1616 <template v-for =" item in bottomIcons " :key =" item .name " >
1717 <button class =" icon" :title =" item.title" @click =" editorIconHandle($event, item.name)" >
1818 <i class =" iconfont" :class =" item.icon" ></i >
2222</template >
2323
2424<script lang="ts">
25- import { defineComponent , nextTick , onMounted , ref , Ref , watch } from ' vue' ;
25+ import { computed , defineComponent , nextTick , onMounted , ref , Ref , watch } from ' vue' ;
2626import { debounce } from ' @/utils' ;
2727import { editorIcons } from ' @/config' ;
2828import { notesState } from ' @/store/notes.state' ;
@@ -35,6 +35,10 @@ export default defineComponent({
3535 windowBlur: {
3636 type: Boolean ,
3737 default: true
38+ },
39+ windowLock: {
40+ type: Boolean ,
41+ default: true
3842 }
3943 },
4044 emits: [' on-input' , ' update:value' ],
@@ -56,12 +60,24 @@ export default defineComponent({
5660 }
5761 }
5862 );
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+ });
5976
6077 // 第一次进入事件
6178 const firstHandle = () => {
6279 nextTick (() => {
6380 focus ();
64- console .dir (editor .value );
6581 editor .value ?.scrollTo (0 , editor .value .scrollHeight );
6682 firstIn .value = false ;
6783 });
@@ -88,11 +104,40 @@ export default defineComponent({
88104 const changeEditorContent = debounce ((e : InputEvent ) => {
89105 const editorHtml = (e .target as Element ).innerHTML ;
90106 emit (' on-input' , editorHtml );
91- }, notesState .syncDelay );
107+ }, notesState .value . syncDelay );
92108
93109 const paste = (e : ClipboardEvent ) => {
94110 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+ }
96141 };
97142
98143 return {
@@ -101,7 +146,8 @@ export default defineComponent({
101146 bottomIcons ,
102147 changeEditorContent ,
103148 paste ,
104- editorContent
149+ editorContent ,
150+ bottomClass
105151 };
106152 }
107153});
0 commit comments