Skip to content

Commit ea839d6

Browse files
committed
Finish Merge from Main
1 parent 1fd71aa commit ea839d6

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController+Lifecycle.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ extension TextViewController {
1616
minimapView.layout()
1717
}
1818

19+
override public func viewDidAppear() {
20+
super.viewDidAppear()
21+
textCoordinators.forEach { $0.val?.controllerDidAppear(controller: self) }
22+
}
23+
24+
override public func viewDidDisappear() {
25+
super.viewDidDisappear()
26+
textCoordinators.forEach { $0.val?.controllerDidDisappear(controller: self) }
27+
}
28+
1929
override public func loadView() {
2030
super.loadView()
2131

@@ -24,7 +34,7 @@ extension TextViewController {
2434

2535
gutterView = GutterView(
2636
configuration: configuration,
27-
textView: textView,
37+
controller: self,
2838
delegate: self
2939
)
3040
gutterView.updateWidthIfNeeded()
@@ -136,7 +146,7 @@ extension TextViewController {
136146
self.gutterView.frame.size.height = self.textView.frame.height + 10
137147
self.gutterView.frame.origin.y = self.textView.frame.origin.y - self.scrollView.contentInsets.top
138148
self.gutterView.needsDisplay = true
139-
self?.gutterView.foldingRibbon.needsDisplay = true
149+
self.gutterView.foldingRibbon.needsDisplay = true
140150
self.reformattingGuideView?.updatePosition(in: self)
141151
self.scrollView.needsLayout = true
142152
}

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class TextViewController: NSViewController {
4848
var localEvenMonitor: Any?
4949
var isPostingCursorNotification: Bool = false
5050

51+
/// A default `NSParagraphStyle` with a set `lineHeight`
52+
lazy var paragraphStyle: NSMutableParagraphStyle = generateParagraphStyle()
53+
5154
// MARK: - Public Variables
5255

5356
/// Passthrough value for the `textView`s string
@@ -170,21 +173,21 @@ public class TextViewController: NSViewController {
170173
/// This will be `nil` if another highlighter provider is passed to the source editor.
171174
internal(set) public var treeSitterClient: TreeSitterClient?
172175

173-
package var fontCharWidth: CGFloat { (" " as NSString).size(withAttributes: [.font: font]).width }
176+
var fontCharWidth: CGFloat { (" " as NSString).size(withAttributes: [.font: font]).width }
174177

175178
/// Filters used when applying edits..
176-
internal var textFilters: [TextFormation.Filter] = []
179+
var textFilters: [TextFormation.Filter] = []
177180

178-
internal var cancellables = Set<AnyCancellable>()
181+
var cancellables = Set<AnyCancellable>()
179182

180183
/// The trailing inset for the editor. Grows when line wrapping is disabled or when the minimap is shown.
181-
package var textViewTrailingInset: CGFloat {
184+
var textViewTrailingInset: CGFloat {
182185
// See https://github.com/CodeEditApp/CodeEditTextView/issues/66
183186
// wrapLines ? 1 : 48
184187
(minimapView?.isHidden ?? false) ? 0 : (minimapView?.frame.width ?? 0.0)
185188
}
186189

187-
package var textViewInsets: HorizontalEdgeInsets {
190+
var textViewInsets: HorizontalEdgeInsets {
188191
HorizontalEdgeInsets(
189192
left: showGutter ? gutterView.frame.width : 0.0,
190193
right: textViewTrailingInset
@@ -249,28 +252,6 @@ public class TextViewController: NSViewController {
249252
self.gutterView.setNeedsDisplay(self.gutterView.frame)
250253
}
251254

252-
// MARK: Paragraph Style
253-
254-
/// A default `NSParagraphStyle` with a set `lineHeight`
255-
package lazy var paragraphStyle: NSMutableParagraphStyle = generateParagraphStyle()
256-
257-
override public func viewWillAppear() {
258-
super.viewWillAppear()
259-
// The calculation this causes cannot be done until the view knows it's final position
260-
updateTextInsets()
261-
minimapView.layout()
262-
}
263-
264-
override public func viewDidAppear() {
265-
super.viewDidAppear()
266-
textCoordinators.forEach { $0.val?.controllerDidAppear(controller: self) }
267-
}
268-
269-
override public func viewDidDisappear() {
270-
super.viewDidDisappear()
271-
textCoordinators.forEach { $0.val?.controllerDidDisappear(controller: self) }
272-
}
273-
274255
deinit {
275256
if let highlighter {
276257
textView.removeStorageDelegate(highlighter)

Sources/CodeEditSourceEditor/Gutter/GutterView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ public class GutterView: NSView {
135135

136136
public convenience init(
137137
configuration: borrowing SourceEditorConfiguration,
138-
textView: TextView,
138+
controller: TextViewController,
139139
delegate: GutterViewDelegate? = nil
140140
) {
141141
self.init(
142142
font: configuration.appearance.font,
143143
textColor: configuration.appearance.theme.text.color,
144144
selectedTextColor: configuration.appearance.theme.selection,
145-
textView: textView,
145+
controller: controller,
146146
delegate: delegate
147147
)
148148
}

Sources/CodeEditSourceEditor/LineFolding/Model/LineFoldCalculator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ actor LineFoldCalculator {
6161
// Depth: Open range
6262
var openFolds: [Int: LineFoldStorage.RawFold] = [:]
6363
var currentDepth: Int = 0
64-
var lineIterator = await ChunkedLineIterator(
64+
let lineIterator = await ChunkedLineIterator(
6565
controller: controller,
6666
foldProvider: foldProvider,
6767
textIterator: await controller.textView.layoutManager.lineStorage.makeIterator()

Sources/CodeEditSourceEditor/LineFolding/Model/LineFoldingModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Combine
2121
class LineFoldingModel: NSObject, NSTextStorageDelegate, ObservableObject {
2222
static let emphasisId = "lineFolding"
2323

24-
2524
/// An ordered tree of fold ranges in a document. Can be traversed using ``FoldRange/parent``
2625
/// and ``FoldRange/subFolds``.
2726
@Published var foldCache: LineFoldStorage = LineFoldStorage(documentLength: 0)

Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Peripherals.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ extension SourceEditorConfiguration {
1616
/// Whether to show the reformatting guide.
1717
public var showReformattingGuide: Bool
1818

19+
/// Whether to show the folding ribbon. Only available if ``showGutter`` is `true`.
20+
public var showFoldingRibbon: Bool
21+
1922
/// Configuration for drawing invisible characters.
2023
///
2124
/// See ``InvisibleCharactersConfiguration`` for more details.
@@ -29,12 +32,14 @@ extension SourceEditorConfiguration {
2932
showGutter: Bool = true,
3033
showMinimap: Bool = true,
3134
showReformattingGuide: Bool = false,
35+
showFoldingRibbon: Bool = true,
3236
invisibleCharactersConfiguration: InvisibleCharactersConfiguration = .empty,
3337
warningCharacters: Set<UInt16> = []
3438
) {
3539
self.showGutter = showGutter
3640
self.showMinimap = showMinimap
3741
self.showReformattingGuide = showReformattingGuide
42+
self.showFoldingRibbon = showFoldingRibbon
3843
self.invisibleCharactersConfiguration = invisibleCharactersConfiguration
3944
self.warningCharacters = warningCharacters
4045
}
@@ -58,6 +63,10 @@ extension SourceEditorConfiguration {
5863
controller.reformattingGuideView.updatePosition(in: controller)
5964
}
6065

66+
if oldConfig?.showFoldingRibbon != showFoldingRibbon {
67+
controller.gutterView.showFoldingRibbon = showFoldingRibbon
68+
}
69+
6170
if oldConfig?.invisibleCharactersConfiguration != invisibleCharactersConfiguration {
6271
controller.invisibleCharactersCoordinator.configuration = invisibleCharactersConfiguration
6372
}

0 commit comments

Comments
 (0)