Skip to content

Commit 6abf9a5

Browse files
committed
fix(ui): 修复 VariableAwareInput 占位符显示问题
- 使用 CodeMirror 6 官方 placeholder 扩展替代 aria-placeholder 方案 - 修复 autosize: true 时高度计算返回对象格式 - 添加 flex 布局支持容器高度自适应 - 更新占位符 CSS 样式使用 .cm-placeholder 选择器
1 parent e29036b commit 6abf9a5

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

packages/ui/src/components/OutputDisplayCore.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@
135135
@update:model-value="handleSourceInput"
136136
:readonly="mode !== 'editable' || streaming"
137137
:placeholder="placeholder"
138-
:autosize="{ minRows: 10, maxRows: 20 }"
138+
:autosize="true"
139139
v-bind="variableData"
140140
@variable-extracted="handleVariableExtracted"
141141
@add-missing-variable="handleAddMissingVariable"
142+
style="height: 100%; min-height: 0;"
142143
/>
143144

144145
<!-- Basic/Image 模式:使用普通输入框 -->

packages/ui/src/components/variable-extraction/VariableAwareInput.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<script setup lang="ts">
5151
import { ref, onMounted, onBeforeUnmount, watch, computed } from 'vue'
5252
53-
import { EditorView, highlightSpecialChars, drawSelection, dropCursor, rectangularSelection, crosshairCursor, keymap } from "@codemirror/view";
53+
import { EditorView, highlightSpecialChars, drawSelection, dropCursor, rectangularSelection, crosshairCursor, keymap, placeholder as cmPlaceholder } from "@codemirror/view";
5454
import { EditorState, Compartment } from "@codemirror/state";
5555
import { history, historyKeymap, defaultKeymap, indentWithTab } from "@codemirror/commands";
5656
import { foldGutter, foldKeymap, indentOnInput, bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
@@ -356,7 +356,11 @@ const handleAddMissingVariable = (varName: string) => {
356356
const editorHeight = computed(() => {
357357
const autosize = props.autosize;
358358
if (typeof autosize === "boolean") {
359-
return autosize ? "auto" : "200px";
359+
// autosize === true 时,完全自适应容器高度(100%)
360+
// autosize === false 时,使用固定高度
361+
return autosize
362+
? { min: '100%', max: 'none' }
363+
: { min: '200px', max: '200px' };
360364
}
361365
const minRows = autosize.minRows || 4;
362366
const maxRows = autosize.maxRows || 12;
@@ -601,11 +605,9 @@ onMounted(() => {
601605
checkSelection();
602606
}
603607
}),
604-
// 占位符
608+
// 占位符(使用官方 placeholder 扩展)
605609
placeholderCompartment.of(
606-
EditorView.contentAttributes.of({
607-
"aria-placeholder": props.placeholder,
608-
}),
610+
props.placeholder ? cmPlaceholder(props.placeholder) : []
609611
),
610612
],
611613
});
@@ -700,9 +702,7 @@ watch(
700702
editorView.dispatch({
701703
effects: [
702704
placeholderCompartment.reconfigure(
703-
EditorView.contentAttributes.of({
704-
"aria-placeholder": placeholder,
705-
}),
705+
placeholder ? cmPlaceholder(placeholder) : []
706706
),
707707
],
708708
});
@@ -824,13 +824,18 @@ defineExpose({
824824
.variable-aware-input-wrapper {
825825
position: relative;
826826
width: 100%;
827+
height: 100%;
828+
display: flex;
829+
flex-direction: column;
827830
}
828831
829832
.codemirror-container {
830833
border: 1px solid var(--n-border-color);
831834
border-radius: var(--n-border-radius);
832835
overflow: hidden;
833836
transition: border-color 0.3s var(--n-bezier);
837+
flex: 1;
838+
min-height: 0;
834839
}
835840
836841
.codemirror-container:hover {
@@ -867,12 +872,11 @@ defineExpose({
867872
word-break: break-word;
868873
}
869874
870-
/* 占位符样式 */
871-
.codemirror-container :deep(.cm-content[aria-placeholder]:empty::before) {
872-
content: attr(aria-placeholder);
875+
/* 占位符样式(使用 CodeMirror 官方 placeholder 扩展) */
876+
.codemirror-container :deep(.cm-placeholder) {
873877
color: var(--n-placeholder-color);
874878
pointer-events: none;
875-
position: absolute;
879+
font-style: italic;
876880
}
877881
878882
/* 自动完成面板样式 */

0 commit comments

Comments
 (0)