From 81bd3ac883090c1c59b35bef995e8cac6a96e312 Mon Sep 17 00:00:00 2001 From: Andrew Kwon Date: Sun, 3 Feb 2019 14:51:11 -0800 Subject: [PATCH 1/5] Record events and dispatch action with workflow --- src/entity.lua | 5 +++-- src/init.lua | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/entity.lua b/src/entity.lua index f3a564f..0ac77a2 100644 --- a/src/entity.lua +++ b/src/entity.lua @@ -276,10 +276,11 @@ end --- Parameters: --- * `mode` - The name of the current mode --- * `shortcut` - A shortcut object containing the keybindings and event handler for the entity +--- * `workflow` - The list of events that compose the current workflow --- --- Returns: --- * A boolean denoting to whether enable or disable automatic mode exit after the action has been dispatched -function Entity:dispatchAction(mode, shortcut) +function Entity:dispatchAction(mode, shortcut, workflow) local flags = shortcut.flags local keyName = shortcut.keyName local eventHandler = self.getEventHandler(self.shortcuts, flags, keyName) @@ -287,7 +288,7 @@ function Entity:dispatchAction(mode, shortcut) if eventHandler then local behaviorFunc = self.behaviors[mode] or self.behaviors.default - return behaviorFunc(self, eventHandler, flags, keyName) + return behaviorFunc(self, eventHandler, flags, keyName, workflow) else return self.autoExitMode end diff --git a/src/init.lua b/src/init.lua index 0f9b9c1..7f069e7 100644 --- a/src/init.lua +++ b/src/init.lua @@ -431,9 +431,18 @@ Ki.statusDisplay = nil -- A table that stores the workflow history. Ki.history = { + workflow = {}, action = {}, } +function Ki.history:recordEvent(mode, keyName, flags) + table.insert(self.workflow, { + mode = mode, + flags = flags, + keyName = keyName, + }) +end + function Ki._renderHotkeyText(modifiers, keyName) local modKeyText = "" local modNames = { @@ -470,6 +479,7 @@ function Ki:_createFsmCallbacks() self.statusDisplay:show(stateMachine.current, parenthetical) if nextState == "desktop" then + self.history.workflow = {} self.history.action = {} end end @@ -512,8 +522,10 @@ function Ki:_handleKeyDown(event) -- Avoid propagating existing handler or non-existent handler in a non-normal mode if handler then + Ki.history:recordEvent(mode, keyName, flags) + if type(handler) == "table" and handler.dispatchAction then - local shouldAutoExit = handler:dispatchAction(mode, Ki.history.action) + local shouldAutoExit = handler:dispatchAction(mode, Ki.history.action, Ki.history.workflow) if shouldAutoExit then self.state:exitMode() From d52d051305edf33ad84df4cb5eb3e1ec4bf44dd0 Mon Sep 17 00:00:00 2001 From: Andrew Kwon Date: Sun, 3 Feb 2019 15:47:59 -0800 Subject: [PATCH 2/5] Add custom behavior in file mode to select files --- docs/html/Entity.html | 1 + docs/markdown/Entity.md | 2 +- src/file.lua | 25 +++++++++++++++++++++++-- src/init.lua | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/html/Entity.html b/docs/html/Entity.html index a611426..d14e551 100644 --- a/docs/html/Entity.html +++ b/docs/html/Entity.html @@ -109,6 +109,7 @@
dispatchAction

Returns: