Skip to content

Commit

Permalink
🐛 Solve the problem of word spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed May 26, 2024
1 parent 3123feb commit 06b1ce7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 0 additions & 6 deletions Mac/View/NotesTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,6 @@ class NotesTableView: NSTableView, NSTableViewDataSource,
return
}
vc.editArea.fill(note: note, highlight: true)

// 用一种新方法设置字间距
if let mutableAttrString = vc.editArea.textStorage {
let range = NSRange(location: 0, length: vc.editArea.string.count)
mutableAttrString.addAttribute(NSAttributedString.Key.kern, value: UserDefaultsManagement.editorLetterSpacing, range: range)
}
}
}
loadingQueue.addOperation(operation)
Expand Down
10 changes: 10 additions & 0 deletions Mac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,16 @@ class ViewController:
}
}

// Used to solve the problem of word spacing
func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool {
if let replacementString = replacementString, replacementString.contains(" ") {
let adjustedString = replacementString.replacingOccurrences(of: " ", with: "\u{00A0}") // 使用不间断空格替代普通空格
textView.textStorage?.replaceCharacters(in: affectedCharRange, with: adjustedString)
return false
}
return true
}

@IBAction func quiteApp(_ sender: Any) {
if UserDefaultsManagement.isSingleMode {
UserDefaultsManagement.isSingleMode = false
Expand Down

0 comments on commit 06b1ce7

Please sign in to comment.