fix(editor): defer mouse presentation activation
This commit is contained in:
parent
771f3368b4
commit
3b9b165464
1 changed files with 14 additions and 3 deletions
|
|
@ -209,7 +209,7 @@ private struct NativeMarkdownTextView: NSViewRepresentable {
|
|||
coordinator?.applyHybridAttributes(to: textView, cause: .focusChange)
|
||||
}
|
||||
textView.onUserEditingInteraction = { [weak coordinator = context.coordinator] textView, interactionKind in
|
||||
coordinator?.activateEditingPresentation(in: textView, interactionKind: interactionKind)
|
||||
coordinator?.recordUserEditingInteraction(interactionKind)
|
||||
}
|
||||
textView.isRichText = false
|
||||
textView.isEditable = true
|
||||
|
|
@ -317,6 +317,9 @@ private struct NativeMarkdownTextView: NSViewRepresentable {
|
|||
guard parent.selection != newSelection else { return }
|
||||
let interactionKind = pendingSelectionInteractionKind ?? lastUserInteractionKind
|
||||
pendingSelectionInteractionKind = nil
|
||||
if interactionKind != .programmatic {
|
||||
hasUserActivatedEditing = true
|
||||
}
|
||||
applyHybridAttributes(to: textView, cause: .selectionChange(interactionKind))
|
||||
parent.selection = newSelection
|
||||
}
|
||||
|
|
@ -417,6 +420,10 @@ private struct NativeMarkdownTextView: NSViewRepresentable {
|
|||
applyHybridAttributes(to: textView, cause: .editingActivation(interactionKind))
|
||||
}
|
||||
|
||||
func recordUserEditingInteraction(_ interactionKind: EditorInteractionKind) {
|
||||
lastUserInteractionKind = interactionKind
|
||||
}
|
||||
|
||||
func setSelection(
|
||||
_ range: NSRange,
|
||||
in textView: NSTextView,
|
||||
|
|
@ -1123,7 +1130,7 @@ public final class HybridMarkdownLiveEditorHarness {
|
|||
coordinator?.applyHybridAttributes(to: textView, cause: .focusChange)
|
||||
}
|
||||
self.textView.onUserEditingInteraction = { [weak coordinator] textView, interactionKind in
|
||||
coordinator?.activateEditingPresentation(in: textView, interactionKind: interactionKind)
|
||||
coordinator?.recordUserEditingInteraction(interactionKind)
|
||||
}
|
||||
self.textView.string = source
|
||||
self.textView.delegate = coordinator
|
||||
|
|
@ -1186,7 +1193,11 @@ public final class HybridMarkdownLiveEditorHarness {
|
|||
}
|
||||
|
||||
private func setSelection(_ range: NSRange, interactionKind: EditorInteractionKind) {
|
||||
coordinator.activateEditingPresentation(in: textView, interactionKind: interactionKind)
|
||||
if interactionKind == .programmatic {
|
||||
coordinator.activateEditingPresentation(in: textView, interactionKind: interactionKind)
|
||||
} else {
|
||||
coordinator.recordUserEditingInteraction(interactionKind)
|
||||
}
|
||||
coordinator.setSelection(range, in: textView, interactionKind: interactionKind)
|
||||
coordinator.textViewDidChangeSelection(Notification(name: NSTextView.didChangeSelectionNotification, object: textView))
|
||||
syncState()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue