fix: Newline renders as yoga carrier (text node) when standalone
Match Ink's behavior where Newline renders as ink-text (yoga carrier). When inside a Text parent, Newline still renders as virtual-text for inline behavior. When standalone, it renders as a text node so it participates in yoga layout and occupies vertical space. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
import { defineComponent, h } from "vue";
|
||||
import { defineComponent, getCurrentInstance, h } from "vue";
|
||||
|
||||
export const Newline = defineComponent({
|
||||
name: "Newline",
|
||||
props: { count: { type: Number, default: 1 } },
|
||||
setup(props) {
|
||||
return () => h("virtual-text", {}, "\n".repeat(props.count));
|
||||
return () => {
|
||||
const content = "\n".repeat(props.count);
|
||||
// Inside a Text parent, render as inline virtual-text.
|
||||
// Outside Text, render as "text" (yoga carrier) so Newline participates
|
||||
// in layout standalone, matching Ink's ink-text behavior.
|
||||
if (isInsideText()) {
|
||||
return h("virtual-text", {}, content);
|
||||
}
|
||||
return h("text", {}, content);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
function isInsideText(): boolean {
|
||||
let parent = getCurrentInstance()?.parent;
|
||||
while (parent) {
|
||||
const name = parent.type && (parent.type as { name?: string }).name;
|
||||
if (name === "Text") return true;
|
||||
parent = parent.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user