From 5d0a8be10ed2ed9c5c49bc1873d0502b5826b795 Mon Sep 17 00:00:00 2001 From: Iron-E Date: Tue, 26 May 2020 00:51:33 -0400 Subject: [PATCH] Cleanup for release candidate --- doc/libmodal-lua.txt | 20 ++++++++++++++++++++ lua/libmodal/src/Layer.lua | 12 ++---------- lua/libmodal/src/collections/Popup.lua | 19 +++++++++---------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/doc/libmodal-lua.txt b/doc/libmodal-lua.txt index 42d3b55..a103cd4 100644 --- a/doc/libmodal-lua.txt +++ b/doc/libmodal-lua.txt @@ -972,6 +972,26 @@ VARIABLES *libmodal-lua-Popup-variables* } < +`self`.buffer *libmodal-lua-Popup.buffer* + + The scratch buffer used by `Popup` to display text. + + Type: ~ + |nvim_create_buf| handle. + + Value: ~ + `vim.api.nvim_create_buf(false, true)` + +`self`.window *libmodal-lua-Popup.window* + + The window used to display the contents of `Popup.buffer`. + + Type: ~ + |nvim_open_win| handle. + + Value: ~ + `vim.api.nvim_open_win(self.buffer, false, Popup.config)` + ------------------------------------------------------------------------------ FUNCTIONS *libmodal-lua-Popup-functions* diff --git a/lua/libmodal/src/Layer.lua b/lua/libmodal/src/Layer.lua index af33025..0ec75c0 100644 --- a/lua/libmodal/src/Layer.lua +++ b/lua/libmodal/src/Layer.lua @@ -4,7 +4,7 @@ */ --]] -local api = vim.api +local api = require('libmodal/src/utils/api') --[[ /* @@ -15,8 +15,8 @@ local api = vim.api local Layer = {['TYPE'] = 'libmodal-layer'} local _BUFFER_CURRENT = 0 +local _ERR_NO_MAP = 'E5555: API call: E31: No such mapping' local _RESTORED = nil -local _ERR_NO_MAP = 'E5555: API call: E31: No such mapping' local function convertKeymap(keymapEntry) local lhs = keymapEntry.lhs @@ -82,11 +82,6 @@ function _metaLayer:enter() end self._priorKeymap = priorKeymap - - local Popup = require('libmodal/src/collections/Popup') - -- TODO: configure `Popup.options` and add the text. - - self._popup = Popup.new() end -------------------------------------------------------- @@ -222,9 +217,6 @@ function _metaLayer:exit() end end self._priorKeymap = _RESTORED - - self._popup:close() - self._popup = nil end --[[ diff --git a/lua/libmodal/src/collections/Popup.lua b/lua/libmodal/src/collections/Popup.lua index 013e964..e6ae97d 100644 --- a/lua/libmodal/src/collections/Popup.lua +++ b/lua/libmodal/src/collections/Popup.lua @@ -38,23 +38,23 @@ local _metaPopup = require('libmodal/src/classes').new(Popup.TYPE) --------------------------- --[[ SUMMARY: - * Close `self._window` + * Close `self.window` * The `self` is inert after calling this. ]] --------------------------- function _metaPopup:close() - api.nvim_win_close(self._window, false) + api.nvim_win_close(self.window, false) - self._buffer = nil + self.buffer = nil self._inputChars = nil - self._window = nil + self.window = nil end ---------------------------------- +--------------------------------------- --[[ SUMMARY: * Update `buffer` with the latest user `inputBytes`. ]] ---------------------------------- +--------------------------------------- function _metaPopup:refresh(inputBytes) local inputBytesLen = #inputBytes local inputChars = self._inputChars @@ -73,7 +73,7 @@ function _metaPopup:refresh(inputBytes) end api.nvim_buf_set_lines( - self._buffer, 0, 1, true, + self.buffer, 0, 1, true, {table.concat(self._inputChars)} ) end @@ -86,13 +86,12 @@ end function Popup.new() local buf = api.nvim_create_buf(false, true) - local Popup = require('libmodal/src/Mode/Popup') return setmetatable( { - ['_buffer'] = buf, + ['buffer'] = buf, ['_inputChars'] = {}, - ['_window'] = api.nvim_call_function( + ['window'] = api.nvim_call_function( 'nvim_open_win', {buf, false, Popup.config} ) },