-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b6c1e
commit 2dab6c2
Showing
4 changed files
with
72 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// SearchField.swift | ||
// CodeEdit | ||
// | ||
// Created by Austin Condiff on 9/3/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SearchField: NSViewRepresentable { | ||
@Binding var text: String | ||
var placeholder: String | ||
|
||
init(_ placeholder: String, text: Binding<String>) { | ||
self.placeholder = placeholder | ||
self._text = text | ||
} | ||
|
||
func makeNSView(context: Context) -> NSSearchField { | ||
let searchField = NSSearchField() | ||
searchField.delegate = context.coordinator | ||
searchField.placeholderString = placeholder | ||
return searchField | ||
} | ||
|
||
func updateNSView(_ nsView: NSSearchField, context: Context) { | ||
nsView.stringValue = text | ||
} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(self) | ||
} | ||
|
||
class Coordinator: NSObject, NSSearchFieldDelegate { | ||
var parent: SearchField | ||
|
||
init(_ parent: SearchField) { | ||
self.parent = parent | ||
} | ||
|
||
func controlTextDidChange(_ obj: Notification) { | ||
if let searchField = obj.object as? NSSearchField { | ||
parent.text = searchField.stringValue | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SearchField("Search", text: .constant("Test")) | ||
} |
58 changes: 0 additions & 58 deletions
58
CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSearchField.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters