Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit 302683f

Browse files
committed
fix: 修复编辑的时候光标错误
1 parent ba47627 commit 302683f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/components/Editor.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</template>
2222

2323
<script lang="ts">
24-
import { defineComponent, onMounted, ref, Ref, watch } from 'vue';
24+
import { defineComponent, nextTick, onMounted, ref, Ref, watch } from 'vue';
2525
import { debounce } from '@/utils';
2626
import { editorIcons } from '@/config';
2727
import { exeConfig } from '@/store/exeConfig.state';
@@ -37,12 +37,28 @@ export default defineComponent({
3737
let editor: Ref<HTMLDivElement | null> = ref(null);
3838
const bottomIcons = editorIcons;
3939
const editorContent: Ref<string | undefined> = ref('');
40+
const firstIn = ref(true);
4041
41-
watch(props, nv => {
42-
if (!editorContent.value) {
43-
editorContent.value = nv.content;
42+
watch(
43+
() => props.content,
44+
newContent => {
45+
if (!editorContent.value) {
46+
editorContent.value = newContent;
47+
}
48+
if (firstIn.value) {
49+
firstHandle();
50+
}
4451
}
45-
});
52+
);
53+
54+
const firstHandle = () => {
55+
nextTick(() => {
56+
focus();
57+
console.dir(editor.value);
58+
editor.value?.scrollTo(0, editor.value.scrollHeight);
59+
firstIn.value = false;
60+
});
61+
};
4662
4763
onMounted(() => {
4864
focus();

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import { sequelizeInit } from './service/initSequelize';
66

77
sequelizeInit();
88

9-
const app = createApp(App);
10-
app.config.errorHandler = outputErrorLog;
11-
app.use(router).mount('#app');
9+
const apps = createApp(App);
10+
apps.config.errorHandler = outputErrorLog;
11+
apps.use(router).mount('#app');

src/store/exeConfig.state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { reactive, watch } from 'vue';
33
const exeConfigLocal = localStorage.getItem('exeConfig');
44

55
export let exeConfig = reactive({
6-
syncDelay: 1000,
6+
syncDelay: 100,
77
serverAddress: '',
88
serverToken: '',
99
switchStatus: {

0 commit comments

Comments
 (0)