Skip to content

Commit 06b1ce7

Browse files
committed
🐛 Solve the problem of word spacing
1 parent 3123feb commit 06b1ce7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Mac/View/NotesTableView.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,6 @@ class NotesTableView: NSTableView, NSTableViewDataSource,
157157
return
158158
}
159159
vc.editArea.fill(note: note, highlight: true)
160-
161-
// 用一种新方法设置字间距
162-
if let mutableAttrString = vc.editArea.textStorage {
163-
let range = NSRange(location: 0, length: vc.editArea.string.count)
164-
mutableAttrString.addAttribute(NSAttributedString.Key.kern, value: UserDefaultsManagement.editorLetterSpacing, range: range)
165-
}
166160
}
167161
}
168162
loadingQueue.addOperation(operation)

Mac/ViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,16 @@ class ViewController:
10081008
}
10091009
}
10101010

1011+
// Used to solve the problem of word spacing
1012+
func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool {
1013+
if let replacementString = replacementString, replacementString.contains(" ") {
1014+
let adjustedString = replacementString.replacingOccurrences(of: " ", with: "\u{00A0}") // 使用不间断空格替代普通空格
1015+
textView.textStorage?.replaceCharacters(in: affectedCharRange, with: adjustedString)
1016+
return false
1017+
}
1018+
return true
1019+
}
1020+
10111021
@IBAction func quiteApp(_ sender: Any) {
10121022
if UserDefaultsManagement.isSingleMode {
10131023
UserDefaultsManagement.isSingleMode = false

0 commit comments

Comments
 (0)