选项命令拖动时未调用 NSTextView 的 textViewDidChangeSelection
NSTextView's textViewDidChangeSelection not called when option-command-dragging
我有一个 NSTextView。
textViewDidChangeSelection 在我拖动以更改选择或如果我命令拖动时被调用,或者如果我选项拖动时被调用,但当我选项命令拖动时不会被调用。
有时日志会输出如下:
[Framework] Shared items array is empty
[Framework] No shared items can be accessed
Option-command-dragging 当然会改变选择,所以我希望在发生 option-command 拖动时得到通知。
“willChangeSelectionFromCharacterRanges”文档说它仅在 setSelectedRange 或 setSelectedRanges 的“stillSelecting”参数设置为 false 时调用。所以我将 NSTextView 子类化以像这样覆盖该参数:
class NeverStillSelectingTextView : NSTextView {
override func setSelectedRanges(_ ranges: [NSValue], affinity: NSSelectionAffinity, stillSelecting stillSelectingFlag: Bool) {
super.setSelectedRanges(ranges, affinity: affinity, stillSelecting: false)
}
override func setSelectedRange(_ charRange: NSRange, affinity: NSSelectionAffinity, stillSelecting stillSelectingFlag: Bool) {
super.setSelectedRange(charRange, affinity: affinity, stillSelecting: false)
}
}
现在 willChangeSelectionFromCharacterRanges 总是在您使用命令选项拖动时调用。
我有一个 NSTextView。
textViewDidChangeSelection 在我拖动以更改选择或如果我命令拖动时被调用,或者如果我选项拖动时被调用,但当我选项命令拖动时不会被调用。
有时日志会输出如下:
[Framework] Shared items array is empty
[Framework] No shared items can be accessed
Option-command-dragging 当然会改变选择,所以我希望在发生 option-command 拖动时得到通知。
“willChangeSelectionFromCharacterRanges”文档说它仅在 setSelectedRange 或 setSelectedRanges 的“stillSelecting”参数设置为 false 时调用。所以我将 NSTextView 子类化以像这样覆盖该参数:
class NeverStillSelectingTextView : NSTextView {
override func setSelectedRanges(_ ranges: [NSValue], affinity: NSSelectionAffinity, stillSelecting stillSelectingFlag: Bool) {
super.setSelectedRanges(ranges, affinity: affinity, stillSelecting: false)
}
override func setSelectedRange(_ charRange: NSRange, affinity: NSSelectionAffinity, stillSelecting stillSelectingFlag: Bool) {
super.setSelectedRange(charRange, affinity: affinity, stillSelecting: false)
}
}
现在 willChangeSelectionFromCharacterRanges 总是在您使用命令选项拖动时调用。