fix: complete task tokens on trailing whitespace
This commit is contained in:
@@ -5,7 +5,7 @@ private let sourceTaskAttachment = NSAttributedString.Key("Conjure.sourceTaskAtt
|
||||
|
||||
private final class TaskAttachment: NSTextAttachment {
|
||||
let marker: String
|
||||
var checked: Bool { !marker.hasSuffix("[ ]") }
|
||||
var checked: Bool { marker.hasSuffix("[x]") || marker.hasSuffix("[X]") }
|
||||
|
||||
@MainActor
|
||||
init(marker: String) {
|
||||
@@ -27,7 +27,7 @@ private final class TaskAttachmentCell: NSTextAttachmentCell {
|
||||
@MainActor
|
||||
final class NotesTextView: NSTextView {
|
||||
private static let taskPattern = try! NSRegularExpression(
|
||||
pattern: "(?m)^[ \\t]*((?:[-+*]|[0-9]+[.)])[ \\t]+\\[([ xX])\\])(?=[ \\t]|\\r?$)"
|
||||
pattern: "(?m)^[ \\t]*((?:[-+*]|[0-9]+[.)])[ \\t]+\\[([ xX]?)\\])(?=[ \\t])"
|
||||
)
|
||||
private var tasks: [(range: NSRange, attachment: TaskAttachment)] = []
|
||||
private var checkboxes: [NSButton] = []
|
||||
@@ -321,8 +321,10 @@ final class NotesTextView: NSTextView {
|
||||
let selection = selectedRange()
|
||||
let marker = task.attachment.marker as NSString
|
||||
let range = markdownRange(for: task.range)
|
||||
let opening = marker.range(of: "[", options: .backwards).location
|
||||
replaceMarkdown(task.attachment.checked ? " " : "x",
|
||||
range: NSRange(location: range.location + marker.length - 2, length: 1))
|
||||
range: NSRange(location: range.location + opening + 1,
|
||||
length: marker.length - opening - 2))
|
||||
setSelectedRange(selection)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user