Skip to content

Commit 7807c51

Browse files
committed
🐛 修复首次光标问题
1 parent ed795bd commit 7807c51

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Mac/View/EditTextView.swift

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ class EditTextView: NSTextView, NSTextFinderClient {
4848
super.drawInsertionPoint(in: newRect, color: EditTextView.fontColor, turnedOn: flag)
4949
}
5050

51+
override func becomeFirstResponder() -> Bool {
52+
let shouldBecomeFirstResponder = super.becomeFirstResponder()
53+
if shouldBecomeFirstResponder && string.isEmpty {
54+
DispatchQueue.main.async {
55+
self.applyParagraphStyle()
56+
}
57+
}
58+
59+
return shouldBecomeFirstResponder
60+
}
61+
5162
override func updateInsertionPointStateAndRestartTimer(_ restartFlag: Bool) {
5263
super.updateInsertionPointStateAndRestartTimer(true)
5364
if let range = selectedRanges[0] as? NSRange, range.length > 0, range != initRange {
@@ -981,6 +992,13 @@ class EditTextView: NSTextView, NSTextFinderClient {
981992
NSWorkspace.shared.open(url)
982993
}
983994

995+
public func applyParagraphStyle() {
996+
let paragraphStyle = NSTextStorage.getParagraphStyle()
997+
typingAttributes[.paragraphStyle] = paragraphStyle
998+
defaultParagraphStyle = paragraphStyle
999+
textStorage?.updateParagraphStyle()
1000+
}
1001+
9841002
override func viewDidChangeEffectiveAppearance() {
9851003
guard let note = EditTextView.note else { return }
9861004
guard let vc = ViewController.shared() else { return }

Mac/ViewController.swift

-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ class ViewController:
495495
.foregroundColor: NSColor(named: "highlight")!,
496496
]
497497
}
498-
499498
editArea.viewDelegate = self
500499
}
501500

@@ -1557,7 +1556,6 @@ class ViewController:
15571556
}
15581557

15591558
// Changed main edit view
1560-
15611559
func textDidChange(_ notification: Notification) {
15621560
guard let note = getCurrentNote() else {
15631561
return

0 commit comments

Comments
 (0)