-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix TextBox unchanged binding writes #5345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
da09166
fda59be
034b95d
2e58388
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import AppKit | ||
| import SwiftUI | ||
| import Testing | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| @MainActor | ||
| struct TextBoxContentSyncTests { | ||
| @Test func contentSyncSkipsUnchangedSwiftUIBindings() { | ||
| var text = "same" | ||
| var attachments: [TextBoxAttachment] = [] | ||
| var height: CGFloat = 24 | ||
| var hasPendingAttachmentUpload = false | ||
| var textWriteCount = 0 | ||
| var attachmentWriteCount = 0 | ||
| var pendingWriteCount = 0 | ||
| var contentChangeCount = 0 | ||
|
|
||
| let inputView = TextBoxInputView( | ||
| text: Binding( | ||
| get: { text }, | ||
| set: { newValue in | ||
| textWriteCount += 1 | ||
| text = newValue | ||
| } | ||
| ), | ||
| attachments: Binding( | ||
| get: { attachments }, | ||
| set: { newValue in | ||
| attachmentWriteCount += 1 | ||
| attachments = newValue | ||
| } | ||
| ), | ||
| textViewHeight: Binding(get: { height }, set: { height = $0 }), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Consider tracking The sibling test ( var heightWriteCount = 0
// ...
textViewHeight: Binding(
get: { height },
set: { newValue in
heightWriteCount += 1
height = newValue
}
),
// ...
`#expect`(heightWriteCount == 0)If height is intentionally excluded because it's layout-derived rather than content-derived, a brief comment explaining that would clarify the test's scope. 🤖 Prompt for AI Agents |
||
| hasPendingAttachmentUpload: Binding( | ||
| get: { hasPendingAttachmentUpload }, | ||
| set: { newValue in | ||
| pendingWriteCount += 1 | ||
| hasPendingAttachmentUpload = newValue | ||
| } | ||
| ), | ||
| font: NSFont.systemFont(ofSize: 14), | ||
| backgroundColor: .textBackgroundColor, | ||
| foregroundColor: .labelColor, | ||
| terminalTitle: "codex", | ||
| completionRootDirectory: nil, | ||
| onSubmit: {}, | ||
| onEscape: {}, | ||
| onFocusTextBox: {}, | ||
| onToggleFocus: {}, | ||
| onForwardText: { _, _ in }, | ||
| onForwardKey: { _ in }, | ||
| onForwardControl: { _ in }, | ||
| onPaste: { _, _ in false }, | ||
| onInsertFileURLs: { _, _ in false }, | ||
| onChooseFiles: {}, | ||
| onContentChanged: { contentChangeCount += 1 }, | ||
| onTextViewCreated: { _ in }, | ||
| onTextViewMovedToWindow: { _ in }, | ||
| onTextViewDismantled: { _ in } | ||
| ) | ||
| let coordinator = TextBoxInputView.Coordinator(parent: inputView) | ||
| let textView = TextBoxInputTextView(frame: NSRect(x: 0, y: 0, width: 320, height: 30)) | ||
| textView.font = NSFont.systemFont(ofSize: 14) | ||
| textView.textColor = .labelColor | ||
| textView.string = "same" | ||
|
|
||
| coordinator.textDidChange(Notification(name: NSText.didChangeNotification, object: textView)) | ||
|
|
||
| #expect(textWriteCount == 0) | ||
| #expect(attachmentWriteCount == 0) | ||
| #expect(pendingWriteCount == 0) | ||
| #expect(contentChangeCount == 0) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 1295
Fix regression commit ordering for the TextBox unchanged-binding write bug.
cmuxTests/TextBoxContentSyncTests.swift(added in commita64519f3) is introduced after the production change (fix: skip unchanged TextBox binding writes, commite200cae7), so the required failing-test-only commit step (CI red) → fix commit step (CI green) isn’t present.🤖 Prompt for AI Agents