Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MarkdownNode } from "react-native-nitro-markdown/headless";
import { CopyTextButton } from "./CopyTextButton";
import { MarkdownTextPrimitive } from "./MarkdownTextPrimitive";
import {
nativeMarkdownDocumentChunks,
nativeMarkdownDocumentRuns,
nativeMarkdownListItemBlocks,
nativeMarkdownNodePosition,
Expand Down Expand Up @@ -57,10 +58,11 @@ function SelectableNode(props: {
readonly skills: ReadonlyArray<SelectableMarkdownSkill>;
readonly textStyle: NativeMarkdownTextStyle;
readonly onLinkPress?: (href: string) => void;
readonly depth?: number;
}) {
return (
<NativeMarkdownSelectableText
runs={nativeMarkdownDocumentRuns(documentFor(props.node), props.skills)}
runs={nativeMarkdownDocumentRuns(documentFor(props.node), props.skills, props.depth)}
textStyle={props.textStyle}
onLinkPress={props.onLinkPress}
/>
Expand Down Expand Up @@ -567,18 +569,34 @@ export function NativeMarkdownBlock(props: {
gap: 6,
}}
>
{(props.node.children ?? []).map((child, index) => (
<NativeMarkdownBlock
key={nodeKey(child, index)}
node={child}
skills={props.skills}
textStyle={props.textStyle}
highlightCode={props.highlightCode}
onLinkPress={props.onLinkPress}
depth={depth}
compact
/>
))}
{/* Consecutive plain children share one text view so selection can
cross paragraphs; iOS selection cannot span separate text views. */}
{nativeMarkdownDocumentChunks({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium src/NativeMarkdownBlock.tsx:573

A list inside a blockquote nested under another list renders with top-level •/◦ markers instead of the expected nested ◦/▪︎ markers and indentation. The selectable chunk path invokes SelectableNode without the enclosing depth, so its nativeMarkdownDocumentRuns call restarts list depth at 1; thread depth through this path when building the runs.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.tsx around line 573:

A list inside a blockquote nested under another list renders with top-level `•`/`◦` markers instead of the expected nested `◦`/`▪︎` markers and indentation. The selectable chunk path invokes `SelectableNode` without the enclosing `depth`, so its `nativeMarkdownDocumentRuns` call restarts list depth at 1; thread `depth` through this path when building the runs.

type: "document",
children: props.node.children ?? [],
}).map((chunk) =>
chunk.kind === "selectable" ? (
<SelectableNode
key={chunk.key}
node={chunk.node}
skills={props.skills}
textStyle={props.textStyle}
onLinkPress={props.onLinkPress}
depth={depth}
/>
) : (
<NativeMarkdownBlock
key={chunk.key}
node={chunk.node}
skills={props.skills}
textStyle={props.textStyle}
highlightCode={props.highlightCode}
onLinkPress={props.onLinkPress}
depth={depth}
compact
/>
),
)}
</View>
);
case "list":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,9 @@ export function nativeMarkdownChunkSpacing(
export function nativeMarkdownDocumentRuns(
node: MarkdownNode,
skills: ReadonlyArray<SelectableMarkdownSkill> = [],
depth = 0,
): ReadonlyArray<NativeMarkdownTextRun> {
const runs = appendDocumentBlock([], node);
const runs = appendDocumentBlock([], node, depth);
while (runs.length > 0) {
const lastIndex = runs.length - 1;
const last = runs[lastIndex];
Expand Down
19 changes: 19 additions & 0 deletions apps/mobile/src/lib/nativeMarkdownText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,25 @@ describe("nativeMarkdownDocumentChunks", () => {
]);
});

it("groups plain blockquote children into one selectable chunk so selection can span paragraphs", () => {
const paragraph = (content: string): MarkdownNode => ({
type: "paragraph",
children: [{ type: "text", content }],
});
const code: MarkdownNode = { type: "code_block", content: "const a = 1;" };

const chunks = nativeMarkdownDocumentChunks({
type: "document",
children: [paragraph("First"), paragraph("Second"), code, paragraph("Third")],
});

expect(chunks.map((chunk) => [chunk.kind, chunk.node.children?.length ?? 0])).toEqual([
["selectable", 2],
["rich", 0],
["selectable", 1],
]);
});

it("keeps headings and plain lists in one selectable document", () => {
const document: MarkdownNode = {
type: "document",
Expand Down
Loading