From e0f14ab7ac21ede9190c1b9e4a278ab65370df1f Mon Sep 17 00:00:00 2001 From: Swoorup Joshi Date: Sun, 1 Nov 2020 02:30:23 +1100 Subject: [PATCH] Support Ctrl-W and Ctrl-U shortcuts in fsi --- src/fsharp/fsi/console.fs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/fsharp/fsi/console.fs b/src/fsharp/fsi/console.fs index cfa95577b7c..ca73d4e121c 100644 --- a/src/fsharp/fsi/console.fs +++ b/src/fsharp/fsi/console.fs @@ -336,6 +336,27 @@ type internal ReadLineConsole() = if (input.Length > 0 && current < input.Length) then input.Remove(current, 1) |> ignore render() + + let deleteFromStartOfLineToCursor() = + if (input.Length > 0 && current > 0) then + input.Remove (0, current) |> ignore + current <- 0 + render() + + let deleteWordLeadingToCursor() = + if (input.Length > 0 && current > 0) then + let line = input.ToString() + let rec prevWord (idx, isInWord) = + if idx < 0 then 0 else + match line.Chars(idx), isInWord with + | ' ', true -> idx + 1 + | ' ', false -> prevWord (idx - 1, false) + | _, _ -> prevWord (idx - 1, true) + + let idx = prevWord (current - 1, false) + input.Remove(idx, current - idx) |> ignore + current <- idx + render() let deleteToEndOfLine() = if (current < input.Length) then @@ -452,6 +473,12 @@ type internal ReadLineConsole() = | (ConsoleModifiers.Control, ConsoleKey.L) -> clear() change() + | (ConsoleModifiers.Control, ConsoleKey.U) -> + deleteFromStartOfLineToCursor() + change() + | (ConsoleModifiers.Control, ConsoleKey.W) -> + deleteWordLeadingToCursor() + change() | _ -> // Note: If KeyChar=0, the not a proper char, e.g. it could be part of a multi key-press character, // e.g. e-acute is ' and e with the French (Belgium) IME and US Intl KB.