Skip to content

Cursor position outside buffer error selecting custom text object in markdown files on branch main #793

@Bekaboo

Description

@Bekaboo

Describe the bug

Selecting around @block.outer with custom textobjects in queries/markdown/textobjects.scm makes nvim throw the following error:

E5108: Error executing lua: ...r-textobjects/lua/nvim-treesitter-textobjects/select.lua:32:
Cursor position outside buffer
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        ...r-textobjects/lua/nvim-treesitter-textobjects/select.lua:32: in function 'update_
selection'
        ...r-textobjects/lua/nvim-treesitter-textobjects/select.lua:174: in function 'sel'
        ....config/nvim/lua/configs/nvim-treesitter-textobjects.lua:34: in function <....con
fig/nvim/lua/configs/nvim-treesitter-textobjects.lua:34>

Put the following in queries/markdown/textobjects.scm in neovim config dir:

(fenced_code_block
  (code_fence_content) @block.inner) @block.outer

To Reproduce
Steps to reproduce the behavior:

  1. Add keymap vim.keymap.set({ 'x', 'o' }, 'a.', function() require('nvim-treesitter-textobjects.select').select_textobject('@block.outer') end)
  2. Create markdown file with a single non-empty code block:
    ```
    echo
    ```
    
  3. Open the markdown file with neovim
  4. Select around block with va.
  5. See the error

Expected behavior

Should not throw error. The custom query works fine on master branch.

Output of :checkhealth nvim-treesitter

============================================================================== nvim-treesitter: ✅

Requirements ~

  • ✅ OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13).
  • ✅ OK tree-sitter 0.25.6 (/opt/homebrew/bin/tree-sitter)
  • ✅ OK node 24.4.1 (/opt/homebrew/bin/node)
  • ✅ OK tar 3.5.3 (/usr/bin/tar)
  • ✅ OK curl 8.7.1 (/usr/bin/curl)
    curl 8.7.1 (x86_64-apple-darwin24.0) libcurl/8.7.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.64.0
    Release-Date: 2024-03-27
    Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
    Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL threadsafe UnixSockets

OS Info ~

  • version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000
  • sysname: Darwin
  • machine: arm64
  • release: 24.6.0

Install directory for parsers and queries ~

  • /Users/shihua.zeng/.local/share/nvim/site/
  • ✅ OK is writable.
  • ✅ OK is in runtimepath.

Installed languages H L F I J ~

  • bash ✓ ✓ ✓ . ✓

  • c ✓ ✓ ✓ ✓ ✓

  • go ✓ ✓ ✓ ✓ ✓

  • lua ✓ ✓ ✓ ✓ ✓

  • markdown ✓ . ✓ ✓ ✓

  • markdown_inline ✓ . . . ✓

  • python ✓ ✓ ✓ ✓ ✓

  • query ✓ ✓ ✓ ✓ ✓

  • vim ✓ ✓ ✓ . ✓

  • vimdoc ✓ . . . ✓

    Legend: H[ighlights], L[ocals], F[olds], I[ndents], In[J]ections ~

Output of nvim --version

NVIM v0.11.2
Build type: Release
LuaJIT 2.1.1748459687

Additional context

The custom query works without error on branch master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions