Skip to content

Find: Replace and Match Case Toggle #301

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "0.1.20"
}
},
{
"identity" : "codeeditsymbols",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditSymbols.git",
"state" : {
"revision" : "ae69712b08571c4469c2ed5cd38ad9f19439793e",
"version" : "0.2.3"
}
},
{
"identity" : "codeedittextview",
"kind" : "remoteSourceControl",
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ let package = Package(
url: "https://github.com/CodeEditApp/CodeEditLanguages.git",
exact: "0.1.20"
),
// CodeEditSymbols
.package(
url: "https://github.com/CodeEditApp/CodeEditSymbols.git",
exact: "0.2.3"
),
// SwiftLint
.package(
url: "https://github.com/lukepistrol/SwiftLintPlugin",
Expand All @@ -43,7 +48,8 @@ let package = Package(
dependencies: [
"CodeEditTextView",
"CodeEditLanguages",
"TextFormation"
"TextFormation",
"CodeEditSymbols"
],
plugins: [
.plugin(name: "SwiftLint", package: "SwiftLintPlugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AppKit
extension TextViewController {
/// Sets new cursor positions.
/// - Parameter positions: The positions to set. Lines and columns are 1-indexed.
public func setCursorPositions(_ positions: [CursorPosition]) {
public func setCursorPositions(_ positions: [CursorPosition], scrollToVisible: Bool = false) {
if isPostingCursorNotification { return }
var newSelectedRanges: [NSRange] = []
for position in positions {
Expand All @@ -33,6 +33,10 @@ extension TextViewController {
}
}
textView.selectionManager.setSelectedRanges(newSelectedRanges)

if scrollToVisible {
textView.scrollSelectionToVisible()
}
}

/// Update the ``TextViewController/cursorPositions`` variable with new text selections from the text view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
// Created by Khan Winter on 3/16/25.
//

import Foundation
import AppKit
import CodeEditTextView

extension TextViewController: FindPanelTarget {
var findPanelTargetView: NSView {
textView
}

func findPanelWillShow(panelHeight: CGFloat) {
updateContentInsets()
}
Expand All @@ -17,6 +21,10 @@ extension TextViewController: FindPanelTarget {
updateContentInsets()
}

func findPanelModeDidChange(to mode: FindPanelMode) {
updateContentInsets()
}

var emphasisManager: EmphasisManager? {
textView?.emphasisManager
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ extension TextViewController {
self.findViewController?.showFindPanel()
return nil
case (0, "\u{1b}"): // Escape key
self.findViewController?.findPanel.dismiss()
self.findViewController?.hideFindPanel()
return nil
case (_, _):
return event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ extension TextViewController {
minimapView.scrollView.contentInsets.bottom += additionalTextInsets?.bottom ?? 0

// Inset the top by the find panel height
let findInset = (findViewController?.isShowingFindPanel ?? false) ? FindPanel.height : 0
let findInset: CGFloat = if findViewController?.viewModel.isShowingFindPanel ?? false {
findViewController?.viewModel.panelHeight ?? 0
} else {
0
}
scrollView.contentInsets.top += findInset
minimapView.scrollView.contentInsets.top += findInset

Expand Down
18 changes: 0 additions & 18 deletions Sources/CodeEditSourceEditor/Find/FindPanelDelegate.swift

This file was deleted.

20 changes: 20 additions & 0 deletions Sources/CodeEditSourceEditor/Find/FindPanelMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FindPanelMode.swift
// CodeEditSourceEditor
//
// Created by Khan Winter on 4/18/25.
//

enum FindPanelMode: CaseIterable {
case find
case replace

var displayName: String {
switch self {
case .find:
return "Find"
case .replace:
return "Replace"
}
}
}
6 changes: 4 additions & 2 deletions Sources/CodeEditSourceEditor/Find/FindPanelTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
// Created by Khan Winter on 3/10/25.
//

import Foundation
import AppKit
import CodeEditTextView

protocol FindPanelTarget: AnyObject {
var emphasisManager: EmphasisManager? { get }
var text: String { get }
var findPanelTargetView: NSView { get }

var cursorPositions: [CursorPosition] { get }
func setCursorPositions(_ positions: [CursorPosition])
func setCursorPositions(_ positions: [CursorPosition], scrollToVisible: Bool)
func updateCursorPosition()

func findPanelWillShow(panelHeight: CGFloat)
func findPanelWillHide(panelHeight: CGFloat)
func findPanelModeDidChange(to mode: FindPanelMode)
}

This file was deleted.

Loading
Loading