Skip to content

Commit 25691d0

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-16995
2 parents cbf9251 + ed3f965 commit 25691d0

265 files changed

Lines changed: 8828 additions & 4147 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/setup-ci-deps/action.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,38 @@ description: Install Vite+ and the workspace dependencies from cache.
33
runs:
44
using: composite
55
steps:
6-
# setup-vp reuses an installed exact version, so restoring its home skips the
7-
# installer download on every job.
6+
# ~/.vite-plus holds vp, the Node.js runtime, and pnpm. A cache entry never
7+
# updates, so the key names all three versions; otherwise a pnpm or Node.js
8+
# bump makes every job download them from npm again.
89
- name: Resolve Vite+ version
910
id: vp
1011
shell: bash
1112
run: |
1213
echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT"
14+
echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT"
15+
echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT"
1316
1417
- name: Cache Vite+
18+
id: vp_cache
1519
if: steps.vp.outputs.version != ''
1620
uses: actions/cache@v6
1721
with:
1822
path: ~/.vite-plus
19-
key: vite-plus-home-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}
23+
key: vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }}
24+
25+
# setup-vp always runs the installer, which fetches vp from npm even when
26+
# this exact version is installed. A cache hit already has everything, so
27+
# skip setup-vp and do its remaining work here. This keeps npm outages from
28+
# failing jobs.
29+
- name: Use cached Vite+
30+
if: steps.vp_cache.outputs.cache-hit == 'true'
31+
shell: bash
32+
run: |
33+
echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH"
34+
"$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}"
2035
2136
- name: Setup Vite+
37+
if: steps.vp_cache.outputs.cache-hit != 'true'
2238
uses: voidzero-dev/setup-vp@v1
2339
with:
2440
node-version-file: package.json

‎.github/workflows/release-desktop.yml‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,13 @@ jobs:
253253
if [[ "${{ inputs.version }}" =~ -nightly\.[0-9]{8}\.[0-9]+$ ]]; then brand=nightly; fi
254254
node scripts/apply-web-brand-assets.ts "$brand" apps/server/dist/client
255255
256-
# The single-executable is built with a Node that supports --build-sea
257-
# (25.7+); the repo itself stays on the engines.node version. A native
258-
# build injects into the runner's own Node; a Windows target downloads its
259-
# node.exe.
256+
# Setup Vite+ selects the exact engines.node version from package.json.
257+
# Native builds embed that executable; cross-target builds download the
258+
# same version for their target.
260259
- name: Build CLI single-executable
261260
if: inputs.cli_archive
262261
shell: bash
263262
env:
264-
# The exact version, not a major: vp downloads it from nodejs.org/dist on
265-
# the runner, and only exact versions have a dist directory. Keep in
266-
# step with SEA_NODE_VERSION in apps/server/vite.config.ts.
267-
VP_NODE_VERSION: "26.8.2"
268263
# The executable bundles the server again, so it needs the same stamp
269264
# as release.yml's JS bundle.
270265
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}

‎.pnpmfile.cjs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
// Release scripts stage their own installs with explicit architectures.
66
module.exports = {
77
hooks: {
8+
// `typescript` is @tsc-rs/typescript (the catalog entry). Its npm version (0.8.x) is outside
9+
// vite-plus-core's typescript peer range, so pnpm gave the vite-plus that @effect/vitest
10+
// imports apps/marketing's [email protected] instead, and tests loaded a second vitest.
11+
readPackage(pkg) {
12+
if (pkg.name === "@voidzero-dev/vite-plus-core" && pkg.peerDependencies?.typescript) {
13+
pkg.peerDependencies.typescript = "*";
14+
}
15+
return pkg;
16+
},
817
updateConfig(config) {
918
// oxlint-disable-next-line t3code/no-global-process-runtime -- pnpm loads this file before any Effect runtime exists.
1019
if (process.platform !== "win32") return config;

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
100100

101101
- Before you push, run `vp run check:changed`. It runs CI's fast checks for changed files: format, lint, knip, typecheck of affected packages and dependents, and tests beside changes. CI still runs the full test suites.
102102
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103-
- Do not use `npx tsc`. Use `vp run typecheck`; it uses tsc-rs, which is 3x faster.
103+
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105105
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
106106
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.

‎apps/desktop/vite.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export default defineConfig({
4343
dependsOn: ["t3#build"],
4444
cache: false,
4545
},
46-
// tsc-rs rewrites the tsbuildinfo it reads, which keeps a task out of the cache.
46+
// tsc (tsc-rs) rewrites the tsbuildinfo it reads, which keeps a task out of the cache.
4747
typecheck: {
48-
command: "tsc-rs --noEmit",
48+
command: "tsc --noEmit",
4949
cache: { input: [{ auto: true }, "!*.tsbuildinfo"] },
5050
},
5151
},
-765 KB
Binary file not shown.
769 KB
Binary file not shown.

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 100 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private struct ComposerTokenPayload: Decodable {
1313
let end: Int
1414
}
1515

16-
private struct ComposerSelectionPayload: Decodable {
16+
private struct ComposerSelectionPayload: Decodable, Equatable {
1717
let start: Int
1818
let end: Int
1919
}
@@ -449,6 +449,9 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
449449
private var tokensNeedRebuild = false
450450
private var chipsNeedMeasuredWidth = false
451451
private var hasDeferredForcedRebuild = false
452+
private var pendingContentOffset: CGPoint?
453+
private var needsSelectionReveal = false
454+
private var selectionBeforeFocusingTap: (selection: ComposerSelectionPayload, value: String)?
452455

453456
let onComposerChange = EventDispatcher()
454457
let onComposerSelectionChange = EventDispatcher()
@@ -464,7 +467,8 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
464467
public required init(appContext: AppContext? = nil) {
465468
super.init(appContext: appContext)
466469

467-
clipsToBounds = false
470+
clipsToBounds = true
471+
textView.clipsToBounds = true
468472
textView.delegate = self
469473
textView.textDropDelegate = self
470474
textView.backgroundColor = .clear
@@ -520,6 +524,12 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
520524
@objc private func openContext(_ recognizer: UITapGestureRecognizer) {
521525
guard let (index, attachment) = contextAttachment(at: recognizer.location(in: textView)) else {
522526
textView.becomeFirstResponder()
527+
if selectionBeforeFocusingTap != nil {
528+
// UIKit places the caret from its own tap recognizer during this same touch.
529+
DispatchQueue.main.async { [weak self] in
530+
self?.restoreSelectionBeforeFocusingTap()
531+
}
532+
}
523533
return
524534
}
525535
openContext(index: index, attachment: attachment)
@@ -558,7 +568,11 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
558568
}
559569

560570
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
561-
true
571+
// The collapsed editor only shows the draft's first line, so a tap that expands an
572+
// overflowing draft returns to the caret it was left at instead of moving it there.
573+
let collapsedOverflow = !textView.isFirstResponder && !textView.isScrollEnabled && draftOverflowsBounds()
574+
selectionBeforeFocusingTap = collapsedOverflow ? (sourceSelection(), value) : nil
575+
return true
562576
}
563577

564578
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
@@ -583,11 +597,27 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
583597

584598
public override func layoutSubviews() {
585599
super.layoutSubviews()
600+
let previousSize = textView.bounds.size
586601
textView.frame = bounds
587602
if chipsNeedMeasuredWidth, bounds.width > 0 {
588603
chipsNeedMeasuredWidth = false
589604
applyControlledDocument(force: true)
590605
}
606+
if textView.isScrollEnabled, bounds.width > 0, bounds.height > 0 {
607+
textView.layoutIfNeeded()
608+
if let offset = pendingContentOffset {
609+
let minY = -textView.adjustedContentInset.top
610+
let maxY = max(minY, textView.contentSize.height - bounds.height + textView.adjustedContentInset.bottom)
611+
textView.setContentOffset(CGPoint(x: offset.x, y: min(maxY, max(minY, offset.y))), animated: false)
612+
pendingContentOffset = nil
613+
}
614+
if needsSelectionReveal || (previousSize != bounds.size && textView.isFirstResponder) {
615+
needsSelectionReveal = false
616+
if let selection = textView.selectedTextRange {
617+
textView.scrollRectToVisible(textView.caretRect(for: selection.end), animated: false)
618+
}
619+
}
620+
}
591621
let placeholderX = textView.textContainerInset.left + textView.textContainer.lineFragmentPadding
592622
let placeholderY = textView.textContainerInset.top
593623
let placeholderWidth = max(
@@ -632,10 +662,12 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
632662
tokens = decode([ComposerTokenPayload].self, from: document.tokensJson) ?? []
633663
tokensNeedRebuild = true
634664
}
665+
let previousSelection = sourceSelection()
635666
value = document.value
636667
requestedSelection = document.selection
637668
applyControlledDocument(force: tokensNeedRebuild)
638669
applyRequestedSelection()
670+
cancelFocusingTapRestoreIfSelectionMoved(from: previousSelection)
639671
if tokensMatchCurrentValue() {
640672
tokensNeedRebuild = false
641673
}
@@ -694,7 +726,16 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
694726
}
695727

696728
func setScrollEnabled(_ scrollEnabled: Bool) {
729+
guard textView.isScrollEnabled != scrollEnabled else { return }
730+
if !scrollEnabled {
731+
// Disabling scrolling discards UITextView's offset. Restore it after
732+
// expansion has laid out the text, regardless of prop update order.
733+
pendingContentOffset = pendingContentOffset ?? textView.contentOffset
734+
}
697735
textView.isScrollEnabled = scrollEnabled
736+
if scrollEnabled {
737+
revealSelectionAfterLayout()
738+
}
698739
}
699740

700741
func setAutoFocus(_ autoFocus: Bool) {
@@ -738,8 +779,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
738779
}
739780

740781
func setSelection(start: Int, end: Int) {
782+
let previousSelection = sourceSelection()
741783
requestedSelection = ComposerSelectionPayload(start: start, end: end)
742784
applyRequestedSelection()
785+
cancelFocusingTapRestoreIfSelectionMoved(from: previousSelection)
743786
}
744787

745788
public func textViewDidChange(_ textView: UITextView) {
@@ -811,6 +854,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
811854
}
812855

813856
public func textViewDidBeginEditing(_ textView: UITextView) {
857+
revealSelectionAfterLayout()
814858
onComposerFocus()
815859
}
816860

@@ -836,13 +880,21 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
836880
hasDeferredForcedRebuild = false
837881

838882
let previousSelection = sourceSelection()
883+
if textView.isScrollEnabled {
884+
pendingContentOffset = pendingContentOffset ?? textView.contentOffset
885+
}
839886
isApplyingControlledValue = true
840887
textView.attributedText = makeAttributedDocument()
841888
let targetSelection = requestedSelection ?? previousSelection
842889
requestedSelection = nil
843890
textView.selectedRange = displayRange(for: targetSelection)
844891
restoreBaseTypingAttributes()
845892
isApplyingControlledValue = false
893+
if currentSource != value || previousSelection.start != targetSelection.start || previousSelection.end != targetSelection.end {
894+
revealSelectionAfterLayout()
895+
} else {
896+
setNeedsLayout()
897+
}
846898
updatePlaceholderVisibility()
847899
emitContentSizeIfNeeded()
848900
}
@@ -1053,6 +1105,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
10531105
return
10541106
}
10551107
value = textView.serializedText()
1108+
revealSelectionAfterLayout()
10561109
let selection = sourceSelection()
10571110
nativeEventCount += 1
10581111
onComposerChange([
@@ -1122,35 +1175,57 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
11221175
isApplyingControlledValue = true
11231176
textView.selectedRange = nextRange
11241177
isApplyingControlledValue = false
1178+
revealSelectionAfterLayout()
1179+
}
1180+
1181+
private func restoreSelectionBeforeFocusingTap() {
1182+
guard let snapshot = selectionBeforeFocusingTap else {
1183+
return
1184+
}
1185+
selectionBeforeFocusingTap = nil
1186+
// A draft that changed during the touch, such as a transcript landing, owns the caret now.
1187+
guard textView.isFirstResponder, textView.markedTextRange == nil, value == snapshot.value else {
1188+
return
1189+
}
1190+
let range = displayRange(for: snapshot.selection)
1191+
guard !NSEqualRanges(range, textView.selectedRange) else {
1192+
return
1193+
}
1194+
textView.selectedRange = range
1195+
revealSelectionAfterLayout()
1196+
}
1197+
1198+
private func cancelFocusingTapRestoreIfSelectionMoved(from previousSelection: ComposerSelectionPayload) {
1199+
if sourceSelection() != previousSelection {
1200+
selectionBeforeFocusingTap = nil
1201+
}
1202+
}
1203+
1204+
private func draftOverflowsBounds() -> Bool {
1205+
let size = textView.sizeThatFits(CGSize(width: textView.bounds.width, height: .greatestFiniteMagnitude))
1206+
return size.height > textView.bounds.height + 1
1207+
}
1208+
1209+
private func revealSelectionAfterLayout() {
1210+
needsSelectionReveal = true
1211+
setNeedsLayout()
11251212
}
11261213

11271214
private func updatePlaceholderVisibility() {
11281215
placeholderLabel.isHidden = !value.isEmpty
11291216
}
11301217

11311218
private func emitContentSizeIfNeeded() {
1132-
// The laid-out text without insets. A one-line draft reports its natural width, so
1133-
// JS can tell whether it fits a narrower row than the one it is laid out in; past
1134-
// one line only the height matters, so layout stops at the second line. The width
1135-
// comes from the line fragment because usedRect spans the container once the view
1136-
// scrolls. A trailing newline's empty line only exists as the extra fragment.
1137-
let layout = textView.layoutManager
1138-
let container = textView.textContainer
1139-
var lines = 0
1140-
var width: CGFloat = 0
1141-
var height: CGFloat = 0
1142-
let glyphs = NSRange(location: 0, length: layout.numberOfGlyphs)
1143-
layout.enumerateLineFragments(forGlyphRange: glyphs) { _, used, _, _, stop in
1144-
lines += 1
1145-
width = used.width
1146-
height = used.maxY
1147-
if lines > 1 { stop.pointee = true }
1148-
}
1149-
if lines < 2, layout.extraLineFragmentTextContainer === container {
1150-
lines += 1
1151-
height = max(height, layout.extraLineFragmentUsedRect.maxY)
1152-
}
1153-
let nextSize = CGSize(width: lines == 1 ? ceil(width) : 0, height: ceil(height))
1219+
guard bounds.width > 0 else { return }
1220+
// Fit independently of the animated viewport: when scrolling is disabled,
1221+
// its current height can clip TextKit's laid-out line fragments.
1222+
let fittedHeight = textView.sizeThatFits(CGSize(width: bounds.width, height: .greatestFiniteMagnitude)).height
1223+
- textView.textContainerInset.top - textView.textContainerInset.bottom
1224+
let measuredHeight = min(lineHeight * 4, fittedHeight)
1225+
let width = fittedHeight <= lineHeight + 0.5
1226+
? textView.layoutManager.usedRect(for: textView.textContainer).width
1227+
: 0
1228+
let nextSize = CGSize(width: ceil(width), height: ceil(measuredHeight))
11541229
guard abs(nextSize.width - lastContentSize.width) > 0.5 ||
11551230
abs(nextSize.height - lastContentSize.height) > 0.5 else {
11561231
return
366 Bytes
Loading
620 Bytes
Loading

0 commit comments

Comments
 (0)