fix: wait for typed separator before completing list markers
This commit is contained in:
@@ -1095,3 +1095,48 @@ func extraListBodyWhitespaceIsVisibleAndHasNormalCursorStops() throws {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test @MainActor
|
||||
func typingMarkersBeforeExistingWhitespaceWaitsForAnExplicitSeparator() throws {
|
||||
_ = NSApplication.shared
|
||||
let editor = NotesTextView(frame: NSRect(x: 0, y: 0, width: 520, height: 200))
|
||||
editor.isRichText = true
|
||||
editor.allowsUndo = true
|
||||
let window = NSWindow(contentRect: editor.frame, styleMask: .borderless, backing: .buffered, defer: false)
|
||||
window.contentView = editor
|
||||
defer { window.orderOut(nil) }
|
||||
window.makeFirstResponder(editor)
|
||||
for marker in ["-", "*", "+", "12.", "9)", "- []", "- [x]"] {
|
||||
for completion in [" ", "\t"] {
|
||||
let prefix = "prose\n \t"
|
||||
let tail = " \t"
|
||||
editor.setMarkdownContents(NSAttributedString(string: prefix + tail))
|
||||
editor.setSelectedRange(NSRange(location: prefix.utf16.count, length: 0))
|
||||
for character in marker {
|
||||
editor.insertText(String(character), replacementRange: editor.selectedRange())
|
||||
}
|
||||
#expect(editor.string == prefix + marker + tail)
|
||||
#expect(editor.markdownString == prefix + marker + tail)
|
||||
editor.breakUndoCoalescing()
|
||||
editor.undoManager?.removeAllActions()
|
||||
editor.insertText(completion, replacementRange: editor.selectedRange())
|
||||
#expect(editor.string == prefix + "\u{fffc}" + completion + tail)
|
||||
#expect(editor.markdownString == prefix + marker + completion + tail)
|
||||
editor.breakUndoCoalescing()
|
||||
editor.undoManager?.undo()
|
||||
#expect(editor.string == prefix + marker + tail)
|
||||
editor.undoManager?.redo()
|
||||
#expect(editor.string == prefix + "\u{fffc}" + completion + tail)
|
||||
editor.insertText("text", replacementRange: editor.selectedRange())
|
||||
#expect(editor.markdownString == prefix + marker + completion + "text" + tail)
|
||||
// Existing Markdown still renders on loading or pasting, without a typing gate.
|
||||
editor.setMarkdownContents(NSAttributedString(string: marker + tail))
|
||||
#expect(editor.string == "\u{fffc}" + tail)
|
||||
editor.setMarkdownContents(NSAttributedString(string: tail))
|
||||
editor.setSelectedRange(NSRange(location: 0, length: 0))
|
||||
editor.insertText(NSAttributedString(string: marker + " pasted"), replacementRange: editor.selectedRange())
|
||||
#expect(editor.string == "\u{fffc} pasted" + tail)
|
||||
#expect(editor.markdownString == marker + " pasted" + tail)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user