Skip to content

Commit

Permalink
move VimHandleEsc function to vim_state.ahk
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmdnk committed Apr 19, 2020
1 parent 254e855 commit 304de7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
22 changes: 1 addition & 21 deletions lib/bind/vim_enter_normal.ahk
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
#If WinActive("ahk_group " . Vim.GroupName)
Esc::VimHandleEsc()
Esc::Vim.State.HandleEsc()
^[::Vim.State.SetNormal()
VimHandleEsc(){
; The keywait waits for esc to be released. If it doesn't detect a release
; within the time limit, sets errorlevel to 1.
KeyWait, Esc, T0.5
LongPress := ErrorLevel
global Vim, VimLongEscNormal
both := VimLongEscNormal && LongPress
neither := !(VimLongEscNormal || LongPress)
SetNormal := both or neither
if (SetNormal) {
Vim.State.SetNormal()
} else {
Send,{Esc}
}
if (LongPress){
; Have to ensure the key has been released, otherwise this will get
; triggered again.
KeyWait, Esc
}
}

#If WinActive("ahk_group " . Vim.GroupName) and (Vim.State.StrIsInCurrentVimMode( "Insert")) and (Vim.Conf["VimJJ"]["val"] == 1)
~j up:: ; jj: go to Normal mode.
Expand Down
21 changes: 21 additions & 0 deletions lib/vim_state.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@
this.SetMode("Vim_Normal")
}

HandleEsc(){
; The keywait waits for esc to be released. If it doesn't detect a release
; within the time limit, sets errorlevel to 1.
KeyWait, Esc, T0.5
LongPress := ErrorLevel
global Vim, VimLongEscNormal
both := VimLongEscNormal && LongPress
neither := !(VimLongEscNormal || LongPress)
SetNormal := both or neither
if (SetNormal) {
Vim.State.SetNormal()
} else {
Send,{Esc}
}
if (LongPress){
; Have to ensure the key has been released, otherwise this will get
; triggered again.
KeyWait, Esc
}
}

IsCurrentVimMode(mode){
this.CheckValidMode(mode)
Return (mode == this.Mode)
Expand Down

0 comments on commit 304de7b

Please sign in to comment.