Skip to content

Commit

Permalink
Support Ctrl-W and Ctrl-U shortcuts in fsi (#10370)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swoorup authored Nov 1, 2020
1 parent 5d9251d commit 4fed162
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/fsharp/fsi/console.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4fed162

Please sign in to comment.