Skip to content
Merged
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
90 changes: 45 additions & 45 deletions Sources/WeiBei/Resources/Editor/editor-entry.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Sources/WeiBei/Resources/Editor/editor-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"assets": [
{
"name": "editor-entry.js",
"bytes": 596356,
"sha256": "fc491f441731389237eb241423e8ab4dd17453b8f5718c46e484d323a7b6fb74"
"bytes": 596509,
"sha256": "e60ac200d47eccca70402ded4f34d3b6d1db557d0eaf64e2c62f90b81cd841f4"
},
{
"name": "editor.css",
Expand Down Expand Up @@ -333,8 +333,8 @@
},
{
"name": "viewer-entry.js",
"bytes": 516964,
"sha256": "046c6a4312333e3e8a91a38bd8a14255d4a618117ef81e8b845bfa8b5717b843"
"bytes": 517117,
"sha256": "d0fd5f23ac0ba5554832a3cc84663ba916efe81781ef93d0af2c2f579f8dbddf"
}
]
}
74 changes: 37 additions & 37 deletions Sources/WeiBei/Resources/Editor/viewer-entry.js

Large diffs are not rendered by default.

35 changes: 25 additions & 10 deletions Sources/WeiBei/Views/NotesAgentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ struct MarkdownPreviewView: View {
@State private var maxObservedMeasuredHeight: CGFloat = 0
@State private var lastLayoutWidthKey = 0
@State private var lastChatWideTypography = false
/// Largest measurement rejected while the finalized-snapshot gate is closed.
/// The web side de-duplicates identical height reports, so one swallowed
/// during the gate would otherwise never arrive again.
@State private var latestGatedHeight: CGFloat = 0

/// Post-streaming height corrections ease instead of snapping: the finalized
/// snapshot and the async re-measures that follow (KaTeX, fonts) can land
Expand Down Expand Up @@ -940,13 +944,6 @@ struct MarkdownPreviewView: View {
onSelectionChange: onSelectionChange,
onAskAgentWithSelection: onSelectionChange,
onContentHeightChange: { height in
guard acceptsHeightMeasurements else {
WeiBeiPerf.event(
"webview.markdown_height_ignored",
extra: "reason=finalizing"
)
return
}
guard compact && fitsContentHeight else {
WeiBeiPerf.event(
"webview.markdown_height_ignored",
Expand All @@ -965,6 +962,19 @@ struct MarkdownPreviewView: View {
}
let measuredHeight = ceil(height)
let nextFrameHeight = max(measuredHeight, Self.compactPreviewLoadingHeight)
guard acceptsHeightMeasurements else {
// Gate window before the finalized snapshot lands. Keep the
// freshest rejected height: the web side dedups repeated
// reports, so one swallowed here never re-arrives, and the
// row would stay at the stale pre-finish height — clipping
// the last wrapped lines after completion.
latestGatedHeight = max(latestGatedHeight, nextFrameHeight)
WeiBeiPerf.event(
"webview.markdown_height_ignored",
extra: "reason=finalizing"
)
return
}
if freezeHeightAfterMeasure, heightFrozen {
// Keep rejecting recycled-row shrink and jitter, but accept
// real late growth from Mermaid, formulas, fonts or images.
Expand Down Expand Up @@ -1034,13 +1044,18 @@ struct MarkdownPreviewView: View {
measuredHeight,
Self.compactPreviewLoadingHeight
)
// Reconcile with measurements rejected during the gate: the
// snapshot may have been read before the finish re-layout, and
// a smaller height clips the answer's last wrapped lines.
let settledHeight = max(nextFrameHeight, latestGatedHeight)
latestGatedHeight = 0
heightFrozen = false
acceptedMeasureCount = 0
applySettledHeight(nextFrameHeight)
maxObservedMeasuredHeight = nextFrameHeight
applySettledHeight(settledHeight)
maxObservedMeasuredHeight = settledHeight
onMeasuredHeight(measuredHeight)
onContentHeightChange()
onFinalizedSnapshotReady(measuredHeight)
onFinalizedSnapshotReady(settledHeight)
},
onRenderFailure: onRenderFailure
)
Expand Down
6 changes: 6 additions & 0 deletions Sources/WeiBei/WebEditor/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2980,6 +2980,12 @@ const finishStreamingMarkdownInternal = (markdown: any) => {
} catch {
// View not ready yet; decorations clear on the next transaction anyway.
}
// Measure synchronously so the height returned to native reflects the
// finalized DOM, not the last streamed report. The finish re-layout can
// grow the document (last wrapped lines, KaTeX), and native reads
// WeiBeiCompactPreviewHeight the instant this call returns — a stale
// smaller value left the completed row clipping its final lines.
publishContentHeight();
scheduleContentHeightReports();
};

Expand Down
17 changes: 14 additions & 3 deletions Sources/WeiBei/WebEditor/src/streaming-appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,22 @@ export function streamingAppearancePlugin(isStreamingActive: () => boolean): Plu
},
},
props: {
// Hidden entirely once the streaming session is over, so the finished
// render never keeps a caret or stale fade spans.
// Once the streaming session is over the caret is gone, but in-flight
// fades keep their spans until they expire so the last streamed
// characters finish their 260ms fade instead of popping to full
// opacity when the finish repaint unwraps the decoration spans.
decorations(state) {
const appearance = appearanceKey.getState(state) as AppearanceState | undefined;
if (!appearance || !isStreamingActive()) return DecorationSet.empty;
if (!appearance) return DecorationSet.empty;
if (!isStreamingActive()) {
const now = Date.now();
const remaining = appearance.fades.filter((entry) => now < entry.expiresAt);
if (remaining.length === 0) return DecorationSet.empty;
return DecorationSet.create(
state.doc,
remaining.map((entry) => Decoration.inline(entry.from, entry.to, FADE_SPEC)),
);
}
return appearance.set;
},
},
Expand Down