Skip to content

Instantly share code, notes, and snippets.

@palmin
Created February 20, 2021 10:36
Show Gist options
  • Save palmin/9e0363cc0704a33194711b43707468d8 to your computer and use it in GitHub Desktop.
Save palmin/9e0363cc0704a33194711b43707468d8 to your computer and use it in GitHub Desktop.
private var constantFloatSelection = NSMakeRange(0, 0)
public override func beginFloatingCursor(at point: CGPoint) {
// remember how it starts out
constantFloatSelection = selectedRange
super.beginFloatingCursor(at: point)
}
public override func updateFloatingCursor(at point: CGPoint) {
// if selection changes during float we set it to something invalid to make
// sure we don't change it back to the old value
if constantFloatSelection != selectedRange {
constantFloatSelection = NSMakeRange(NSNotFound, 0)
}
super.updateFloatingCursor(at: point)
}
public override func endFloatingCursor() {
if constantFloatSelection == selectedRange {
showMenuFromSelection()
}
super.endFloatingCursor()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment