Skip to content

Commit 72b7064

Browse files
committed
✨ 增强输入的性能移除格式变化
1 parent 7807c51 commit 72b7064

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

Mac/View/EditTextView.swift

+5-16
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class EditTextView: NSTextView, NSTextFinderClient {
5151
override func becomeFirstResponder() -> Bool {
5252
let shouldBecomeFirstResponder = super.becomeFirstResponder()
5353
if shouldBecomeFirstResponder && string.isEmpty {
54-
DispatchQueue.main.async {
55-
self.applyParagraphStyle()
56-
}
54+
let paragraphStyle = NSTextStorage.getParagraphStyle()
55+
typingAttributes[.paragraphStyle] = paragraphStyle
56+
defaultParagraphStyle = paragraphStyle
5757
}
5858

5959
return shouldBecomeFirstResponder
@@ -63,7 +63,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
6363
super.updateInsertionPointStateAndRestartTimer(true)
6464
if let range = selectedRanges[0] as? NSRange, range.length > 0, range != initRange {
6565
DispatchQueue.main.async {
66-
self.textStorage?.updateParagraphStyle()
6766
self.initRange = range
6867
}
6968
}
@@ -99,7 +98,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
9998

10099
if initRange.length > 0 {
101100
DispatchQueue.main.async {
102-
self.textStorage?.updateParagraphStyle()
103101
self.initRange = NSRange(location: 0, length: 0)
104102
}
105103
}
@@ -239,7 +237,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
239237
breakUndoCoalescing()
240238
saveTextStorageContent(to: note)
241239
fillHighlightLinks()
242-
textStorage?.updateParagraphStyle()
243240
return
244241
}
245242

@@ -397,8 +394,8 @@ class EditTextView: NSTextView, NSTextFinderClient {
397394

398395
undoManager?.removeAllActions(withTarget: self)
399396

400-
if let appd = NSApplication.shared.delegate as? AppDelegate,
401-
let md = appd.mainWindowController {
397+
if let appDelegate = NSApplication.shared.delegate as? AppDelegate,
398+
let md = appDelegate.mainWindowController {
402399
md.editorUndoManager = note.undoManager
403400
}
404401

@@ -800,7 +797,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
800797
NotesTextProcessor.highlightMarkdown(attributedString: storage, note: note)
801798
saveTextStorageContent(to: note)
802799
note.save()
803-
textStorage?.updateParagraphStyle()
804800
}
805801
viewDelegate?.notesTableView.reloadRow(note: note)
806802

@@ -992,13 +988,6 @@ class EditTextView: NSTextView, NSTextFinderClient {
992988
NSWorkspace.shared.open(url)
993989
}
994990

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

0 commit comments

Comments
 (0)