From fd69ebfaad252b4485918f6bfc98c2c09265cb9f Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Sun, 15 Jun 2025 08:33:19 -0600 Subject: [PATCH] (renderer) keymap bugfix --- lua/u/renderer.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lua/u/renderer.lua b/lua/u/renderer.lua index 9219115..c50aec4 100644 --- a/lua/u/renderer.lua +++ b/lua/u/renderer.lua @@ -1,4 +1,4 @@ -local Signal = require('u.tracker').Signal +function _G.URendererOpFuncSwallow() end local M = {} local H = {} @@ -243,12 +243,20 @@ function Renderer:render(tree) -- {{{ for lhs, _ in pairs(tag.attributes[mode .. 'map'] or {}) do -- Force creating an extmark if there are key handlers. To accurately -- sense the bounds of the text, we need an extmark: - vim.keymap.set( - mode, - lhs, - function() return self:_expr_map_callback(mode, lhs) end, - { buffer = self.bufnr, expr = true, replace_keycodes = true } - ) + vim.keymap.set(mode, lhs, function() + local result = self:_expr_map_callback(mode, lhs) + -- If the handler indicates that it wants to swallow the event, + -- we have to convert that intention into something compatible + -- with expr-mappings, which don't support '' (they try to + -- execute the literal characters). We'll use the 'g@' operator + -- to do that, forwarding the event to an operatorfunc that does + -- nothing: + if result == '' then + vim.go.operatorfunc = 'v:lua.URendererOpFuncSwallow' + return 'g@ ' + end + return result + end, { buffer = self.bufnr, expr = true, replace_keycodes = true }) end end @@ -509,7 +517,7 @@ function TreeBuilder:put_h(name, attributes, children) return self end ---- @param fn fun(TreeBuilder): any +--- @param fn fun(tb: u.renderer.TreeBuilder): any --- @return u.renderer.TreeBuilder function TreeBuilder:nest(fn) local nested_writer = TreeBuilder.new()