Skip to content

feat: Find in Editor #295

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

Merged
merged 41 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a10ba6f
Add search manager and search field
tom-ludwig Mar 10, 2025
d920eb6
Add Search Container, Search Bar, Show/Hide Commands, Animations
thecoolwinter Mar 11, 2025
5800d05
Set Initial Search Bar Constraints Correctly
thecoolwinter Mar 11, 2025
1488a86
Add search manager and search field
tom-ludwig Mar 10, 2025
dc5e6d8
Add Search Container, Search Bar, Show/Hide Commands, Animations
thecoolwinter Mar 11, 2025
5842295
Set Initial Search Bar Constraints Correctly
thecoolwinter Mar 11, 2025
fd16af7
Renamed SearchBar to FindPanel. Styled FindPanel. Added number of mat…
austincondiff Mar 12, 2025
d62a0c1
Add dark theme to example app
austincondiff Mar 13, 2025
1f9beb6
Fixed background
austincondiff Mar 13, 2025
ae89966
Adjusted font in example app
austincondiff Mar 13, 2025
41d7180
Simplified example app
austincondiff Mar 14, 2025
9ed65d6
Merge branch 'feat/in-doc-search' of https://github.com/CodeEditApp/C…
thecoolwinter Mar 16, 2025
8a028a3
Fix Text Scrolling Under Panel, Fix Resizing Bug, Fix Test
thecoolwinter Mar 16, 2025
66035bf
Addded Bezel Notification to editor and firing a bezel notification w…
austincondiff Mar 17, 2025
66d8508
Enabled anti-aliasing and font smoothing for line numbers. Changed li…
austincondiff Mar 20, 2025
deebe23
Highlight the closes element to the users cursor
tom-ludwig Mar 20, 2025
fb2c670
Add documentation
tom-ludwig Mar 20, 2025
968a4e9
Fix linter
tom-ludwig Mar 22, 2025
cd0a8b9
Renamed EmphasisAPI to EmphasisManager. Separated concerns by moving …
austincondiff Mar 28, 2025
0695d43
Fixed merge conflict issue.
austincondiff Mar 28, 2025
9d493df
Unified keybinding observer logic which fixed a bug where find keybin…
austincondiff Mar 29, 2025
813531e
Fixed issue where keybindings would apply to other windows editors.
austincondiff Mar 31, 2025
114c6e9
Remove Unused Variable
thecoolwinter Mar 31, 2025
56f37c0
Renamed find panel cancel actions to dismiss.
austincondiff Apr 3, 2025
40b7660
Fixed SwiftLint errors and split files up.
austincondiff Apr 3, 2025
0980ef0
Update tests.sh
austincondiff Apr 3, 2025
3ec17ec
Update tests.sh
austincondiff Apr 3, 2025
f74d2e8
Update tests.sh
austincondiff Apr 3, 2025
1d75296
Use `selectInDocument` over `select`
thecoolwinter Apr 3, 2025
c349cd6
Merge branch 'main' into feat/in-doc-search
thecoolwinter Apr 3, 2025
1dc6c3b
Replace Safe Area With Top Padding, Smoother Animations
thecoolwinter Apr 7, 2025
56acf85
Merge branch 'main' into feat/in-doc-search
thecoolwinter Apr 7, 2025
ed43078
Add Find Panel Height when Setting Up Scroll View
thecoolwinter Apr 7, 2025
4099499
Clean Up Animation Code
thecoolwinter Apr 7, 2025
9ad415c
Rename
thecoolwinter Apr 7, 2025
08445ee
Strongly Reference Self in Monitor
thecoolwinter Apr 7, 2025
909eabc
Update Package.resolved
thecoolwinter Apr 7, 2025
a7cb556
Use Constants For Emphasis Groups, Add `additionalInsets`, Correctly …
thecoolwinter Apr 7, 2025
d89d6b8
Lint Error
thecoolwinter Apr 7, 2025
168d278
Fixing the lint cause the lint to be mad :-1:
thecoolwinter Apr 7, 2025
0aba812
Merge branch 'main' into feat/in-doc-search
thecoolwinter Apr 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
61621C612C74FB2200494A4A /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 61621C602C74FB2200494A4A /* CodeEditSourceEditor */; };
61CE772F2D19BF7D00908C57 /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 61CE772E2D19BF7D00908C57 /* CodeEditSourceEditor */; };
61CE77322D19BFAA00908C57 /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 61CE77312D19BFAA00908C57 /* CodeEditSourceEditor */; };
6C13652E2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13652D2B8A7B94004A1D18 /* CodeEditSourceEditorExampleApp.swift */; };
6C1365302B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C13652F2B8A7B94004A1D18 /* CodeEditSourceEditorExampleDocument.swift */; };
6C1365322B8A7B94004A1D18 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1365312B8A7B94004A1D18 /* ContentView.swift */; };
Expand Down Expand Up @@ -41,6 +43,8 @@
buildActionMask = 2147483647;
files = (
61621C612C74FB2200494A4A /* CodeEditSourceEditor in Frameworks */,
61CE772F2D19BF7D00908C57 /* CodeEditSourceEditor in Frameworks */,
61CE77322D19BFAA00908C57 /* CodeEditSourceEditor in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -140,6 +144,8 @@
name = CodeEditSourceEditorExample;
packageProductDependencies = (
61621C602C74FB2200494A4A /* CodeEditSourceEditor */,
61CE772E2D19BF7D00908C57 /* CodeEditSourceEditor */,
61CE77312D19BFAA00908C57 /* CodeEditSourceEditor */,
);
productName = CodeEditSourceEditorExample;
productReference = 6C13652A2B8A7B94004A1D18 /* CodeEditSourceEditorExample.app */;
Expand Down Expand Up @@ -412,6 +418,14 @@
isa = XCSwiftPackageProductDependency;
productName = CodeEditSourceEditor;
};
61CE772E2D19BF7D00908C57 /* CodeEditSourceEditor */ = {
isa = XCSwiftPackageProductDependency;
productName = CodeEditSourceEditor;
};
61CE77312D19BFAA00908C57 /* CodeEditSourceEditor */ = {
isa = XCSwiftPackageProductDependency;
productName = CodeEditSourceEditor;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 6C1365222B8A7B94004A1D18 /* Project object */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ struct CodeEditSourceEditorExampleApp: App {
DocumentGroup(newDocument: CodeEditSourceEditorExampleDocument()) { file in
ContentView(document: file.$document, fileURL: file.fileURL)
}
.windowToolbarStyle(.unifiedCompact)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AppKit
import CodeEditSourceEditor

extension EditorTheme {
static var standard: EditorTheme {
static var light: EditorTheme {
EditorTheme(
text: Attribute(color: NSColor(hex: "000000")),
insertionPoint: NSColor(hex: "000000"),
Expand All @@ -25,9 +25,29 @@ extension EditorTheme {
variables: Attribute(color: NSColor(hex: "0F68A0")),
values: Attribute(color: NSColor(hex: "6C36A9")),
numbers: Attribute(color: NSColor(hex: "1C00CF")),
strings: Attribute(color: NSColor(hex: "C41A16"), bold: true, italic: true),
strings: Attribute(color: NSColor(hex: "C41A16")),
characters: Attribute(color: NSColor(hex: "1C00CF")),
comments: Attribute(color: NSColor(hex: "267507"), italic: true)
comments: Attribute(color: NSColor(hex: "267507"))
)
}
static var dark: EditorTheme {
EditorTheme(
text: Attribute(color: NSColor(hex: "FFFFFF")),
insertionPoint: NSColor(hex: "007AFF"),
invisibles: Attribute(color: NSColor(hex: "53606E")),
background: NSColor(hex: "292A30"),
lineHighlight: NSColor(hex: "2F3239"),
selection: NSColor(hex: "646F83"),
keywords: Attribute(color: NSColor(hex: "FF7AB2"), bold: true),
commands: Attribute(color: NSColor(hex: "78C2B3")),
types: Attribute(color: NSColor(hex: "6BDFFF")),
attributes: Attribute(color: NSColor(hex: "CC9768")),
variables: Attribute(color: NSColor(hex: "4EB0CC")),
values: Attribute(color: NSColor(hex: "B281EB")),
numbers: Attribute(color: NSColor(hex: "D9C97C")),
strings: Attribute(color: NSColor(hex: "FF8170")),
characters: Attribute(color: NSColor(hex: "D9C97C")),
comments: Attribute(color: NSColor(hex: "7F8C98"))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,121 @@ import CodeEditLanguages
import CodeEditTextView

struct ContentView: View {
@Environment(\.colorScheme)
var colorScheme

@Binding var document: CodeEditSourceEditorExampleDocument
let fileURL: URL?

@State private var language: CodeLanguage = .default
@State private var theme: EditorTheme = .standard
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular)
@State private var theme: EditorTheme = .light
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .medium)
@AppStorage("wrapLines") private var wrapLines: Bool = true
@State private var cursorPositions: [CursorPosition] = []
@State private var cursorPositions: [CursorPosition] = [.init(line: 1, column: 1)]
@AppStorage("systemCursor") private var useSystemCursor: Bool = false
@State private var isInLongParse = false
@State private var settingsIsPresented: Bool = false
@State private var treeSitterClient = TreeSitterClient()

init(document: Binding<CodeEditSourceEditorExampleDocument>, fileURL: URL?) {
self._document = document
self.fileURL = fileURL
}

var body: some View {
VStack(spacing: 0) {
HStack {
Text("Language")
LanguagePicker(language: $language)
.frame(maxWidth: 100)
Toggle("Wrap Lines", isOn: $wrapLines)
if #available(macOS 14, *) {
Toggle("Use System Cursor", isOn: $useSystemCursor)
} else {
Toggle("Use System Cursor", isOn: $useSystemCursor)
.disabled(true)
.help("macOS 14 required")
GeometryReader { proxy in
CodeEditSourceEditor(
$document.text,
language: language,
theme: theme,
font: font,
tabWidth: 4,
lineHeight: 1.2,
wrapLines: wrapLines,
cursorPositions: $cursorPositions,
useThemeBackground: true,
highlightProviders: [treeSitterClient],
contentInsets: NSEdgeInsets(top: proxy.safeAreaInsets.top, left: 0, bottom: 28.0, right: 0),
useSystemCursor: useSystemCursor
)
.overlay(alignment: .bottom) {
HStack {
Menu {
Toggle("Wrap Lines", isOn: $wrapLines)
if #available(macOS 14, *) {
Toggle("Use System Cursor", isOn: $useSystemCursor)
} else {
Toggle("Use System Cursor", isOn: $useSystemCursor)
.disabled(true)
.help("macOS 14 required")
}
} label: {}
.background {
Image(systemName: "switch.2")
.foregroundStyle(.secondary)
.font(.system(size: 13.5, weight: .regular))
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(maxWidth: 18, alignment: .center)
Spacer()
Group {
if isInLongParse {
HStack(spacing: 5) {
ProgressView()
.controlSize(.small)
Text("Parsing Document")
}
} else {
Text(getLabel(cursorPositions))
}
}
.foregroundStyle(.secondary)
Divider()
.frame(height: 12)
LanguagePicker(language: $language)
.buttonStyle(.borderless)
}
Spacer()
Text(getLabel(cursorPositions))
}
.padding(4)
.zIndex(2)
.background(Color(NSColor.windowBackgroundColor))
Divider()
ZStack {
if isInLongParse {
.font(.subheadline)
.fontWeight(.medium)
.controlSize(.small)
.padding(.horizontal, 8)
.frame(height: 28)
.background(.bar)
.overlay(alignment: .top) {
VStack {
HStack {
Spacer()
Text("Parsing document...")
Spacer()
}
.padding(4)
.background(Color(NSColor.windowBackgroundColor))
Spacer()
Divider()
.overlay {
if colorScheme == .dark {
Color.black
}
}
}
.zIndex(2)
.transition(.opacity)
}
CodeEditSourceEditor(
$document.text,
language: language,
theme: theme,
font: font,
tabWidth: 4,
lineHeight: 1.2,
wrapLines: wrapLines,
cursorPositions: $cursorPositions,
useSystemCursor: useSystemCursor
)
.zIndex(2)
.onAppear {
self.language = detectLanguage(fileURL: fileURL) ?? .default
self.theme = colorScheme == .dark ? .dark : .light
}
}
}
.onAppear {
self.language = detectLanguage(fileURL: fileURL) ?? .default
}
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParse)) { _ in
withAnimation(.easeIn(duration: 0.1)) {
isInLongParse = true
.ignoresSafeArea()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParse)) { _ in
withAnimation(.easeIn(duration: 0.1)) {
isInLongParse = true
}
}
}
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParseFinished)) { _ in
withAnimation(.easeIn(duration: 0.1)) {
isInLongParse = false
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParseFinished)) { _ in
withAnimation(.easeIn(duration: 0.1)) {
isInLongParse = false
}
}
.onChange(of: colorScheme) { _, newValue in
if newValue == .dark {
theme = .dark
} else {
theme = .light
}
}
}
}
Expand All @@ -105,7 +144,7 @@ struct ContentView: View {
/// - Returns: A string describing the user's location in a document.
func getLabel(_ cursorPositions: [CursorPosition]) -> String {
if cursorPositions.isEmpty {
return ""
return "No cursor"
}

// More than one selection, display the number of selections.
Expand Down
8 changes: 4 additions & 4 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
// A fast, efficient, text view for code.
.package(
url: "https://github.com/CodeEditApp/CodeEditTextView.git",
from: "0.8.1"
from: "0.8.2"
),
// tree-sitter languages
.package(
Expand Down
Loading