Skip to content

bug: encode_selection_prompt in visual mode incorrectly captures selection -- Bad interaction with telescope-ui-select #38

Description

@diegobit

Did you check docs and existing issues?

  • I have read all the docs
  • I have searched the existing issues
  • I have searched the existing issues of plugins related to this issue (if relevant)

Neovim version (nvim -v)

NVIM v0.11.7 - Release

Operating system/version

MacOS Tahoe 26.4

Describe the bug

I have require('decipher').encode_selection_prompt { preview = false } set in a keymap in visual mode:

vim.keymap.set('v', '<leader>ce', function()
  require('decipher').encode_selection_prompt { preview = false }
end, { desc = 'Encode Selected Text' })

but, when using it, nothing happens, unless I have previously set a selection.

If preview = true, then I get this error:

Error executing vim.schedule lua callback: .../share/nvim/lazy/decipher.nvim/lua/decipher/ui/float.lua:275: 'height' key must be a positive Integer
stack traceback:
        [C]: in function 'nvim_win_set_config'
        .../share/nvim/lazy/decipher.nvim/lua/decipher/ui/float.lua:275: in function 'render_page'
        .../share/nvim/lazy/decipher.nvim/lua/decipher/ui/float.lua:407: in function 'switch_to_page'
        .../share/nvim/lazy/decipher.nvim/lua/decipher/ui/float.lua:538: in function 'open'
        ...ocal/share/nvim/lazy/decipher.nvim/lua/decipher/init.lua:87: in function 'open_float_handler'
        ...ocal/share/nvim/lazy/decipher.nvim/lua/decipher/init.lua:135: in function 'process_codec'
        ...ocal/share/nvim/lazy/decipher.nvim/lua/decipher/init.lua:151: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

The plugin works with a minimal repro.lua, but doesn't with telescope-ui-select. Probably that plugin is not passing the selection to decipher? Not sure who the culprit is.


I attach a video as well

Screen.Recording.2026-04-01.at.09.21.57.mp4

Notes:

I'm using the most recent version of decipher from add-commands branch. Here's some info.

Lazy Log:

    ○ decipher.nvim 
        ba9ae0c Add tests for invalid command arguments (4 days ago)
        44d123d Remove print statement (5 days ago)
        459a13c Minor type fixes (5 days ago)
        33f1db4 Add commands (5 days ago)
        be80ebe Bump to v3.0.0 (#35) (6 weeks ago)
        adb89de Support writeback (#33) (9 weeks ago)
        2f511f2 Bump to v2.1.0 (#34) (6 months ago)
        9e92ebd Add codecs from vim-unimpaired (#30) (6 months ago)

Decipher config:

vim.keymap.set('n', '<leader>ce', function()
  require('decipher').encode_motion_prompt { preview = false }
end, { desc = 'Encode (w/ motion)' })
vim.keymap.set('n', '<leader>cd', function()
  require('decipher').decode_motion_prompt { preview = false }
end, { desc = 'Decode (w/ motion)' })
vim.keymap.set('v', '<leader>ce', function()
  require('decipher').encode_selection_prompt { preview = true }
end, { desc = 'Encode Selected Text' })
vim.keymap.set('v', '<leader>cd', function()
  require('decipher').decode_selection_prompt { preview = true }
end, { desc = 'Decode Selected Text' })

vim.keymap.set({ 'v' }, 'gbe', function()
  require('decipher').encode_selection ('base64', { preview = false })
  local keys = vim.api.nvim_replace_termcodes('<ESC>', true, false, true)
  vim.api.nvim_feedkeys(keys, 'm', false)
end, { noremap = true, silent = true, desc = 'Encode' })
vim.keymap.set({ 'v' }, 'gbd', function()
  require('decipher').decode_selection ('base64', { preview = false })
end, { noremap = true, silent = true, desc = 'Decode' })

vim.keymap.set({ 'v' }, 'gbse', function()
  require('decipher').encode_selection ('base64-url-safe', { preview = false })
end, { noremap = true, silent = true, desc = 'Encode' })
vim.keymap.set({ 'v' }, 'gbsd', function()
  require('decipher').decode_selection ('base64-url-safe', { preview = false })
end, { noremap = true, silent = true, desc = 'Decode' })

vim.keymap.set({ 'v' }, 'g/e', function()
  require('decipher').encode_selection ('url', { preview = false })
end, { noremap = true, silent = true, desc = 'Encode' })
vim.keymap.set({ 'v' }, 'g/d', function()
  require('decipher').decode_selection ('url', { preview = false })
end, { noremap = true, silent = true, desc = 'Decode' })

return {
  'MisanthropicBit/decipher.nvim',
  -- version = '*',
  branch = 'add-commands',
  -- event = 'VeryLazy',
  lazy = true, -- Load with keymap
  config = function()
    local decipher = require 'decipher'
    decipher.setup {
      active_codecs = 'all',
      float = {
        border = {
          { '┌', 'FloatBorder' },
          { '─', 'FloatBorder' },
          { '┐', 'FloatBorder' },
          { '│', 'FloatBorder' },
          { '┘', 'FloatBorder' },
          { '─', 'FloatBorder' },
          { '└', 'FloatBorder' },
          { '│', 'FloatBorder' },
        },

        mappings = {
          close = 'q',
          apply = 'y',
          jsonpp = 'J', -- Key to prettily format contents as json if possbile
          help = '?',
        },
        enter = true,
        options = {},
      },
    }
  end,
}

Output of :checkhealth decipher

==============================================================================
decipher: 1 ❌

  • ❌ ERROR No healthcheck found for "decipher" plugin.

Steps To Reproduce

Steps to get empty behaviour:

  1. nvim -u repro.lua
  2. write anything*
  3. visual mode, select some text (eg. word 'second')
  4. trigger decipher keymap for encode_selection_prompt (base64)
  5. nothing happens

Steps to see it's not getting the new selection:

  1. nvim -u repro.lua
  2. write anything*
  3. visual mode, select some text (eg. word 'second')
  4. , go back to normal mode
  5. now visual mode, select some OTHER text (eg. word 'third')
  6. trigger decipher keymap for encode_selection_prompt (base64)
  7. the previously selected text gets encoded ('second' becomes 'c2Vjb25k')

*My example:

some text
on a second line
and a third line

Expected Behavior

Selected text in visual mode gets correctly encoded

Repro

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath,
  })
end

vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " "

vim.keymap.set("v", "<leader>ce", function()
  require("decipher").encode_selection_prompt({ preview = false })
end, { desc = "Encode Selected Text" })

require("lazy").setup({
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope-ui-select.nvim",
    },
    config = function()
      require("telescope").setup({
        extensions = {
          ["ui-select"] = require("telescope.themes").get_dropdown({}),
        },
      })

      pcall(require("telescope").load_extension, "ui-select")
    end,
  },
  {
    "MisanthropicBit/decipher.nvim",
    branch = "add-commands",
    lazy = true,
    config = function()
      require("decipher").setup({})
    end,
  },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions