feat: refresh string value keep scrolltop
This commit is contained in:
parent
cb9a9ebb8a
commit
62c0079a8d
|
@ -24,7 +24,9 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['reset', 'input', 'save'])
|
const emit = defineEmits(['reset', 'input', 'save', 'scroll'])
|
||||||
|
|
||||||
|
const scrollTop = ref(0)
|
||||||
|
|
||||||
const themeVars = useThemeVars()
|
const themeVars = useThemeVars()
|
||||||
/** @type {HTMLElement|null} */
|
/** @type {HTMLElement|null} */
|
||||||
|
@ -71,6 +73,7 @@ onMounted(async () => {
|
||||||
scrollbar: {
|
scrollbar: {
|
||||||
useShadows: false,
|
useShadows: false,
|
||||||
verticalScrollbarSize: '10px',
|
verticalScrollbarSize: '10px',
|
||||||
|
alwaysConsumeMouseWheel: true,
|
||||||
},
|
},
|
||||||
// formatOnType: true,
|
// formatOnType: true,
|
||||||
contextmenu: false,
|
contextmenu: false,
|
||||||
|
@ -86,6 +89,13 @@ onMounted(async () => {
|
||||||
// add shortcut for save
|
// add shortcut for save
|
||||||
editorNode.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, (event) => {
|
editorNode.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, (event) => {
|
||||||
emit('save')
|
emit('save')
|
||||||
|
});
|
||||||
|
|
||||||
|
editorNode.onDidScrollChange((event) => {
|
||||||
|
// 防止刷新时改变滚动距离
|
||||||
|
if (!event.scrollHeightChanged) {
|
||||||
|
scrollTop.value = event.scrollTop;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// editorNode.onDidChangeModelLanguageConfiguration(() => {
|
// editorNode.onDidChangeModelLanguageConfiguration(() => {
|
||||||
|
@ -105,6 +115,12 @@ watch(
|
||||||
async (content) => {
|
async (content) => {
|
||||||
if (editorNode != null) {
|
if (editorNode != null) {
|
||||||
editorNode.setValue(content)
|
editorNode.setValue(content)
|
||||||
|
editorNode.onDidLayoutChange(() => {
|
||||||
|
if (scrollTop.value > 0) {
|
||||||
|
console.log(scrollTop.value);
|
||||||
|
editorNode.setScrollTop(scrollTop.value);
|
||||||
|
}
|
||||||
|
})
|
||||||
await nextTick(() => emit('reset', content))
|
await nextTick(() => emit('reset', content))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue