diff --git a/src/codemp.lua b/src/codemp.lua index 8a7145f..f6f9e1f 100644 --- a/src/codemp.lua +++ b/src/codemp.lua @@ -92,10 +92,10 @@ local function buffer_get_content(buf) return table.concat(lines, '\n') end --- local function buffer_set_content(buf, content) --- local lines = split_without_trim(content, "\n") --- vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) --- end +local function buffer_set_content(buf, content) + local lines = split_without_trim(content, "\n") + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) +end local function buffer_replace_content(buffer, first, last, content) -- TODO send help it works but why is lost knowledge @@ -259,6 +259,23 @@ vim.api.nvim_create_user_command( { nargs = 1 } ) +vim.api.nvim_create_user_command( + "Sync", + function (args) + local buffer = vim.api.nvim_get_current_buf() + local name = buffer_mappings[buffer] + if name ~= nil then + local controller = codemp.get_buffer(name) + codemp_changed_tick = vim.api.nvim_buf_get_changedtick(buffer) + 1 + buffer_set_content(buffer, controller.content) + print(" :: synched buffer " .. name) + else + print(" !! buffer not managed") + end + end, + { } +) + vim.api.nvim_create_user_command( "Detach", function (args) diff --git a/src/lib.rs b/src/lib.rs index a2daa5a..4180256 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -156,10 +156,7 @@ impl LuaUserData for LuaBufferController { } fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) { - fields.add_field_method_get("content", |_, this| Ok( - this.0.try_recv().map(|x| x.map(|y| y.content)) - .map_err(LuaCodempError::from)? - )); + fields.add_field_method_get("content", |_, this| Ok(this.0.content())); } }