Skip to content

Commit 96f33ab

Browse files
committed
fix (core): 修复编辑器显示混乱问题
1 parent 33ae1ed commit 96f33ab

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/App.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
<div class="flex-1 flex overflow-hidden">
1414
<!-- 代码编辑器 -->
15-
<div class="flex-1 flex flex-col">
16-
<div class="bg-gray-100 px-4 py-2 border-b border-gray-200 flex items-center justify-between">
15+
<div class="flex-1 flex flex-col overflow-hidden">
16+
<div class="bg-gray-100 px-4 py-2 border-b border-gray-200 flex items-center justify-between flex-shrink-0">
1717
<h2 class="text-sm font-medium text-gray-700">{{ getLanguageDisplayName(currentLanguage) }} 代码编辑器</h2>
1818
<div class="text-xs text-gray-500">
1919
<strong>{{ code.length }}</strong> 字符, <strong>{{ code.split('\n').length }}</strong> 行
2020
</div>
2121
</div>
22-
<CodeEditor v-model="code" class="flex-1" :language="currentLanguage"/>
22+
<div class="flex-1 overflow-hidden">
23+
<CodeEditor v-model="code" class="h-full" :language="currentLanguage"/>
24+
</div>
2325
</div>
2426

2527
<!-- 输出 -->

src/components/CodeEditor.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<template>
2-
<div class="flex bg-white h-full relative">
2+
<div class="flex bg-white h-full relative overflow-hidden">
33
<!-- 行号 -->
44
<div ref="lineNumbersRef"
5-
class="bg-gray-50 text-gray-400 text-sm font-mono py-4 px-3 select-none border-r border-gray-200 overflow-hidden flex-shrink-0 z-10">
5+
class="bg-gray-50 text-gray-400 text-sm font-mono px-3 pb-4 select-none border-r border-gray-200 overflow-hidden flex-shrink-0 z-10"
6+
style="padding-top: 0;">
67
<div v-for="(num, index) in lineNumbers" :key="index" class="h-6 leading-6 text-right">
78
{{ num }}
89
</div>
910
</div>
1011

1112
<!-- 语法高亮容器 -->
12-
<div class="flex-1 relative">
13+
<div class="flex-1 relative overflow-hidden">
1314
<!-- 高亮显示层 -->
1415
<pre ref="highlightRef"
15-
class="absolute inset-0 p-4 font-mono text-sm leading-6 bg-transparent pointer-events-none overflow-hidden whitespace-pre-wrap z-0"
16-
style="margin: 0; border: 0; word-break: break-word; white-space: pre-wrap;"
16+
class="absolute inset-0 px-4 pb-4 font-mono text-sm leading-6 bg-transparent pointer-events-none overflow-auto whitespace-pre-wrap z-0"
17+
style="margin: 0; border: 0; padding-top: 0; word-break: break-word; white-space: pre-wrap;"
1718
v-html="highlightedCode"></pre>
1819

1920
<!-- 代码输入框 -->
@@ -22,8 +23,8 @@
2223
@input="handleInput"
2324
@keydown="handleKeyDown"
2425
@scroll="handleScroll"
25-
class="absolute inset-0 p-4 font-mono text-sm leading-6 resize-none outline-none bg-transparent z-10"
26-
style="color: transparent; caret-color: #374151; margin: 0; border: 0; word-break: break-word; white-space: pre-wrap;"
26+
class="absolute inset-0 px-4 pb-4 font-mono text-sm leading-6 resize-none outline-none bg-transparent z-10 overflow-auto"
27+
style="color: transparent; caret-color: #374151; margin: 0; border: 0; padding-top: 0; word-break: break-word; white-space: pre-wrap;"
2728
placeholder="在此输入代码..."
2829
spellcheck="false">
2930
</textarea>

0 commit comments

Comments
 (0)