fix: complete task tokens on trailing whitespace

This commit is contained in:
Valdemar Lorenzen
2026-10-19 12:32:23 +02:00
parent 7c26a88c6c
commit f275695d2f
4 changed files with 75 additions and 4 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ final class NotesController: NSViewController, NSTextViewDelegate {
}
private static let listItem = try! NSRegularExpression(
pattern: "^([ \\t]*)([-+*]|([0-9]+)([.)]))([ \\t]+|$)(?:\\[([ xX])\\]([ \\t]+|$))?"
pattern: "^([ \\t]*)([-+*]|([0-9]+)([.)]))([ \\t]+|$)(?:\\[([ xX]?)\\]([ \\t]+|$))?"
)
private static func indentationWidth(_ indentation: String) -> Int {
+5 -3
View File
@@ -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)
}
}