From 52ef216f0442d973112158d8329f36d250ef5d82 Mon Sep 17 00:00:00 2001 From: Nicolas Crespo Date: Thu, 12 Mar 2026 01:41:48 -0700 Subject: [PATCH 1/2] fix(nvim-events): skip notifications for non-file buffers --- app/nvim/on-content-change.ts | 27 +++++++++++++++------------ app/nvim/on-cursor-move.ts | 29 ++++++++++++++++------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/app/nvim/on-content-change.ts b/app/nvim/on-content-change.ts index b91928e..4363694 100644 --- a/app/nvim/on-content-change.ts +++ b/app/nvim/on-content-change.ts @@ -30,18 +30,21 @@ export async function onContentChange( } }); - // Create autocmd to notify us with event "attach_buffer" - await app.nvim.call("nvim_create_autocmd", [ - ["InsertEnter", "TextChanged"], - { - group: app.augroupId, - desc: "Notify github-preview", - command: `lua - local buffer = vim.api.nvim_get_current_buf() - local path = vim.api.nvim_buf_get_name(0) - vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path)`, - }, - ]); + // Create autocmd to notify us with event "attach_buffer" + await app.nvim.call("nvim_create_autocmd", [ + ["InsertEnter", "TextChanged"], + { + group: app.augroupId, + desc: "Notify github-preview", + command: `lua + local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) + if buftype == "" then + local buffer = vim.api.nvim_get_current_buf() + local path = vim.api.nvim_buf_get_name(0) + vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path) + end`, + }, + ]); // "nvim_buf_lines_event" and "nvim_buf_changedtick_event" events are // only emitted by neovim if we've attached a buffer. diff --git a/app/nvim/on-cursor-move.ts b/app/nvim/on-cursor-move.ts index d2e53be..dd0a765 100644 --- a/app/nvim/on-cursor-move.ts +++ b/app/nvim/on-cursor-move.ts @@ -11,17 +11,20 @@ export async function onCursorMove( // Notification handler app.nvim.onNotification(NOTIFICATION, callback); - // Create autocmd to notify us with event "CursorMove" - await app.nvim.call("nvim_create_autocmd", [ - ["CursorHold", "CursorHoldI"], - { - group: app.augroupId, - desc: "Notify github-preview", - command: `lua - local buffer = vim.api.nvim_get_current_buf() - local path = vim.api.nvim_buf_get_name(0) - local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path, cursor_line)`, - }, - ]); + // Create autocmd to notify us with event "CursorMove" + await app.nvim.call("nvim_create_autocmd", [ + ["CursorHold", "CursorHoldI"], + { + group: app.augroupId, + desc: "Notify github-preview", + command: `lua + local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) + if buftype == "" then + local buffer = vim.api.nvim_get_current_buf() + local path = vim.api.nvim_buf_get_name(0) + local cursor_line = vim.api.nvim_win_get_cursor(0)[1] + vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path, cursor_line) + end`, + }, + ]); } From 317c396e2eef749c67fae1d5f1f2fc6bbb3c9ca8 Mon Sep 17 00:00:00 2001 From: wallpants <47203170+wallpants@users.noreply.github.com> Date: Sun, 31 May 2026 03:03:00 -0600 Subject: [PATCH 2/2] style(formatter): run formatter --- app/nvim/on-content-change.ts | 24 ++++++++++++------------ app/nvim/on-cursor-move.ts | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/nvim/on-content-change.ts b/app/nvim/on-content-change.ts index 4363694..b95494e 100644 --- a/app/nvim/on-content-change.ts +++ b/app/nvim/on-content-change.ts @@ -30,21 +30,21 @@ export async function onContentChange( } }); - // Create autocmd to notify us with event "attach_buffer" - await app.nvim.call("nvim_create_autocmd", [ - ["InsertEnter", "TextChanged"], - { - group: app.augroupId, - desc: "Notify github-preview", - command: `lua + // Create autocmd to notify us with event "attach_buffer" + await app.nvim.call("nvim_create_autocmd", [ + ["InsertEnter", "TextChanged"], + { + group: app.augroupId, + desc: "Notify github-preview", + command: `lua local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) if buftype == "" then - local buffer = vim.api.nvim_get_current_buf() - local path = vim.api.nvim_buf_get_name(0) - vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path) + local buffer = vim.api.nvim_get_current_buf() + local path = vim.api.nvim_buf_get_name(0) + vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path) end`, - }, - ]); + }, + ]); // "nvim_buf_lines_event" and "nvim_buf_changedtick_event" events are // only emitted by neovim if we've attached a buffer. diff --git a/app/nvim/on-cursor-move.ts b/app/nvim/on-cursor-move.ts index dd0a765..9d510ae 100644 --- a/app/nvim/on-cursor-move.ts +++ b/app/nvim/on-cursor-move.ts @@ -11,20 +11,20 @@ export async function onCursorMove( // Notification handler app.nvim.onNotification(NOTIFICATION, callback); - // Create autocmd to notify us with event "CursorMove" - await app.nvim.call("nvim_create_autocmd", [ - ["CursorHold", "CursorHoldI"], - { - group: app.augroupId, - desc: "Notify github-preview", - command: `lua - local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) - if buftype == "" then - local buffer = vim.api.nvim_get_current_buf() - local path = vim.api.nvim_buf_get_name(0) - local cursor_line = vim.api.nvim_win_get_cursor(0)[1] - vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path, cursor_line) - end`, - }, - ]); + // Create autocmd to notify us with event "CursorMove" + await app.nvim.call("nvim_create_autocmd", [ + ["CursorHold", "CursorHoldI"], + { + group: app.augroupId, + desc: "Notify github-preview", + command: `lua + local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 }) + if buftype == "" then + local buffer = vim.api.nvim_get_current_buf() + local path = vim.api.nvim_buf_get_name(0) + local cursor_line = vim.api.nvim_win_get_cursor(0)[1] + vim.rpcnotify(${app.nvim.channelId}, "${NOTIFICATION}", buffer, path, cursor_line) + end`, + }, + ]); }