Skip to content

Commit

Permalink
auto ime engagement
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 13, 2021
1 parent b8d12c1 commit 78ff162
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ FVimUIMessages v:false " external messages -- not implemented
FVimUITermColors v:false " not implemented
FVimUIHlState v:false " not implemented
" Keyboard mapping options
FVimKeyDisableShiftSpace v:true " disable unsupported sequence <S-Space>
FVimKeyAutoIme v:true " Automatic input method engagement in Insert mode
" Detach from a remote session without killing the server
" If this command is executed on a standalone instance,
" the embedded process will be terminated anyway.
Expand Down
17 changes: 17 additions & 0 deletions Views/Grid.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open FVim.ui
open FVim.wcwidth
open FVim.def
open FVim.common

open ReactiveUI
open Avalonia
Expand Down Expand Up @@ -36,6 +37,7 @@ type Grid() as this =
static let ViewModelProperty = AvaloniaProperty.Register<Grid, GridViewModel>("ViewModel")
static let GridIdProperty = AvaloniaProperty.Register<Grid, int>("GridId")
static let RenderTickProperty = AvaloniaProperty.Register<Grid, int>("RenderTick")
static let EnableImeProperty = AvaloniaProperty.Register<Grid, bool>("EnableIme")

let mutable grid_fb: RenderTargetBitmap = null
let mutable grid_dc: IDrawingContextImpl = null
Expand All @@ -49,6 +51,7 @@ type Grid() as this =

let ev_cursor_rect_changed = Event<EventHandler,EventArgs>()
let ev_text_view_visual_changed = Event<EventHandler,EventArgs>()
let ev_active_state_changed = Event<EventHandler,EventArgs>()

// !Only call this if VisualRoot is attached
let resizeFrameBuffer() =
Expand Down Expand Up @@ -218,6 +221,10 @@ type Grid() as this =
trace grid_vm "render tick %d" id
this.InvalidateVisual())

this.GetObservable(EnableImeProperty).Subscribe(fun _ ->
ev_active_state_changed.Trigger(this, EventArgs.Empty)
)

vm.ObservableForProperty(fun x -> x.IsFocused)
|> Observable.subscribe(fun focused ->
if focused.Value && not this.IsFocused then
Expand Down Expand Up @@ -351,6 +358,9 @@ type Grid() as this =
grid_vm.MarkAllDirty()
this.InvalidateVisual())

rpc.register.notify "EnableIme" (fun [| Bool(v) |] ->
this.EnableIme <- v)

// Input handling
this.TextInput |> subscribeAndHandleInput(fun e vm -> vm.OnTextInput e)
this.KeyDown |> subscribeAndHandleInput(fun e vm -> vm.OnKey e)
Expand Down Expand Up @@ -428,8 +438,10 @@ type Grid() as this =

member _.CursorRectangle: Rect = m_cursor.Bounds
member _.TextViewVisual: IVisual = this :> IVisual
member _.ActiveState = this.EnableIme
[<CLIEvent>] member _.CursorRectangleChanged: IEvent<EventHandler,EventArgs> = ev_cursor_rect_changed.Publish
[<CLIEvent>] member _.TextViewVisualChanged: IEvent<EventHandler,EventArgs> = ev_text_view_visual_changed.Publish
[<CLIEvent>] member _.ActiveStateChanged: IEvent<EventHandler,EventArgs> = ev_active_state_changed.Publish

member this.GridId
with get () = this.GetValue(GridIdProperty)
Expand All @@ -439,4 +451,9 @@ type Grid() as this =
with get() = this.GetValue(RenderTickProperty)
and set(v) = this.SetValue(RenderTickProperty, v) |> ignore

member this.EnableIme
with get() = this.GetValue(EnableImeProperty)
and set(v) =
this.SetValue(EnableImeProperty, v) |> ignore

static member GetGridIdProp() = GridIdProperty
5 changes: 5 additions & 0 deletions model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ let Start (serveropts, norc, debugMultigrid) =
rpc.register.bool "cursor.smoothblink"
rpc.register.bool "cursor.smoothmove"
rpc.register.bool "key.disableShiftSpace"
rpc.register.bool "key.autoIme"
//rpc.register.bool "ui.multigrid"
rpc.register.bool "ui.popupmenu"
//rpc.register.bool "ui.tabline"
Expand Down Expand Up @@ -481,6 +482,7 @@ let Start (serveropts, norc, debugMultigrid) =
let! _ = nvim.``command!`` "-complete=expression FVimFontBoldWeight" 1 "call rpcnotify(g:fvim_channel, 'font.weight.bold', <args>)"
let! _ = nvim.``command!`` "-complete=expression FVimFontNoBuiltinSymbols" 1 "call rpcnotify(g:fvim_channel, 'font.nonerd', <args>)"
let! _ = nvim.``command!`` "-complete=expression FVimKeyDisableShiftSpace" 1 "call rpcnotify(g:fvim_channel, 'key.disableShiftSpace', <args>)"
let! _ = nvim.``command!`` "-complete=expression FVimKeyAutoIme" 1 "call rpcnotify(g:fvim_channel, 'key.autoIme', <args>)"

//let! _ = nvim.``command!`` "-complete=expression FVimUIMultiGrid" 1 "call rpcnotify(g:fvim_channel, 'ui.multigrid', <args>)"
let! _ = nvim.``command!`` "-complete=expression FVimUIPopupMenu" 1 "call rpcnotify(g:fvim_channel, 'ui.popupmenu', <args>)"
Expand Down Expand Up @@ -548,6 +550,9 @@ let OnGridReady(gridui: IGridUI) =
async {
let! _ = nvim.set_var "fvim_render_scale" gridui.RenderScale
let! _ = nvim.ui_attach gridui.GridWidth gridui.GridHeight
let! _ = nvim.command "execute \"autocmd InsertEnter * call rpcnotify(g:fvim_channel, 'EnableIme', v:true)\""
let! _ = nvim.command "execute \"autocmd InsertLeave * call rpcnotify(g:fvim_channel, 'EnableIme', v:false)\""

in ()
} |> runAsync

Expand Down
1 change: 1 addition & 0 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let mutable channel_id = 1

// keyboard mapping
let mutable key_disableShiftSpace = false
let mutable key_autoIme = false

// clipboard
let mutable clipboard_lines: string[] = [||]
Expand Down

0 comments on commit 78ff162

Please sign in to comment.