Allow clicking to position cursor within current command
- Can now click anywhere in the current command line to edit - Useful for editing commands from history - Clicking before prompt automatically moves cursor to prompt position - Prevents editing previous output
This commit is contained in:
@@ -355,6 +355,15 @@ class TerminalSession: NSObject, NSTextViewDelegate, NSMenuDelegate {
|
||||
return result
|
||||
}
|
||||
|
||||
func textViewDidChangeSelection(_ notification: Notification) {
|
||||
// Allow cursor to be positioned anywhere in the current command
|
||||
// But if user clicks before the prompt, move cursor to prompt position
|
||||
let selectedRange = textView.selectedRange()
|
||||
if selectedRange.location < promptPosition && selectedRange.length == 0 {
|
||||
textView.setSelectedRange(NSRange(location: promptPosition, length: 0))
|
||||
}
|
||||
}
|
||||
|
||||
private func getCurrentCommand() -> String {
|
||||
guard promptPosition <= textView.string.count else { return "" }
|
||||
let startIndex = textView.string.index(textView.string.startIndex, offsetBy: promptPosition)
|
||||
|
||||
Reference in New Issue
Block a user