Skip to content

Commit

Permalink
fix #221, temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Mar 20, 2022
1 parent f7a0eb5 commit c044e35
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions input.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open neovim

open Avalonia.Input
open System
open System.Runtime.InteropServices
open FSharp.Control.Reactive
open Avalonia.Interactivity

Expand Down Expand Up @@ -94,6 +95,7 @@ let DIR (dx: float, dy: float, horizontal: bool) =

let mutable accumulatedX = 0.0
let mutable accumulatedY = 0.0
let mutable blockNextTextInput = false

// Avoid sending Rejected key as a sequence, e.g. "capslock"
let RejectKeys = set [
Expand Down Expand Up @@ -285,7 +287,7 @@ let (|Special|Normal|Rejected|) (x: InputEvent) =
// | ' | ' | ä |
// | Ctrl-' | <C-'> | <C-'> |
//
| Key(m, Key.Back) -> Special "BS"
| Key(_, Key.Back) -> Special "BS"
| Key(_, Key.Tab) -> Special "Tab"
| Key(_, Key.LineFeed) -> Special "NL"
| Key(_, Key.Return) -> Special "CR"
Expand Down Expand Up @@ -359,8 +361,14 @@ let (|Special|Normal|Rejected|) (x: InputEvent) =
| Key(_, Key.Divide) -> Special("kDivide")
| Key(_, Key.Separator) -> Special("kEnter")
| Key(_, Key.Decimal) -> Special("kPoint")
| Key(NoFlag(KeyModifiers.Shift), x) -> Normal (x.ToString().ToLowerInvariant())
| Key(_, x) -> Normal (x.ToString())
| Key(NoFlag(KeyModifiers.Shift) as m, x) ->
if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && m = KeyModifiers.Alt
then blockNextTextInput <- true
Normal (x.ToString().ToLowerInvariant())
| Key(m, x) ->
if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && m = (KeyModifiers.Alt ||| KeyModifiers.Shift)
then blockNextTextInput <- true
Normal (x.ToString())
| _ -> Rejected

let rec ModifiersPrefix (x: InputEvent) =
Expand Down Expand Up @@ -398,7 +406,11 @@ let onInput (nvim: Nvim) (input: IObservable<int*InputEvent*RoutedEventArgs>) =
match x with
| TextInput txt ->
ev.Handled <- true
if txt = "<" then Some "<LT>" else Some txt
if blockNextTextInput then
blockNextTextInput <- false
None
elif txt = "<" then Some "<LT>"
else Some txt
| InputEvent.Key _ ->
ev.Handled <- true
let pref = ModifiersPrefix x
Expand Down

0 comments on commit c044e35

Please sign in to comment.