diff --git a/lua/orgmode/init.lua b/lua/orgmode/init.lua index 2321ddd20..af7110806 100644 --- a/lua/orgmode/init.lua +++ b/lua/orgmode/init.lua @@ -1,5 +1,5 @@ _G.orgmode = _G.orgmode or {} -local ts_revision = '1c3eb533a9cf6800067357b59e03ac3f91fc3a54' +local ts_revision = '9a595e51c1f69b9ac986f0e0b788804eda0e755d' local setup_ts_grammar_used = false local instance = nil @@ -75,10 +75,10 @@ local function setup_ts_grammar(revision) end local function check_ts_grammar() - if setup_ts_grammar_used then - return - end vim.defer_fn(function() + if setup_ts_grammar_used then + return + end local parser_config = require('nvim-treesitter.parsers').get_parser_configs() if parser_config and parser_config.org and parser_config.org.install_info.revision ~= ts_revision then require('orgmode.utils').echo_error({ diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index 74fbada73..79d5159c3 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -454,16 +454,26 @@ function OrgMappings:handle_return(suffix) item = Files.get_current_file():get_current_node() end - if item.type == 'itemtext' or item.type == 'bullet' or item.type == 'checkbox' or item.type == 'description' then + if item.type == 'paragraph' or item.type == 'bullet' then local list_item = item.node:parent() if list_item:type() ~= 'listitem' then return end local line = vim.fn.getline(list_item:start() + 1) local end_row, _ = list_item:end_() + local next_line_node = current_file:get_node_at_cursor({ end_row + 1, 0 }) + local second_line_node = current_file:get_node_at_cursor({ end_row + 2, 0 }) + local is_end_of_file = next_line_node + and vim.tbl_contains({ 'paragraph', 'list' }, next_line_node:type()) + and second_line_node + and second_line_node:type() == 'document' + -- Range for list items at the very end of the file are not calculated properly + if (end_row + 1) == vim.fn.line('$') and is_end_of_file then + end_row = end_row + 1 + end local range = { - start = { line = end_row + 1, character = 0 }, - ['end'] = { line = end_row + 1, character = 0 }, + start = { line = end_row, character = 0 }, + ['end'] = { line = end_row, character = 0 }, } local checkbox = line:match('^(%s*[%+%-])%s*%[[%sXx%-]?%]') @@ -512,7 +522,7 @@ function OrgMappings:handle_return(suffix) if #text_edits > 0 then vim.lsp.util.apply_text_edits(text_edits, 0, constants.default_offset_encoding) - vim.fn.cursor(end_row + 2 + (add_empty_line and 1 or 0), 0) -- +1 for 0 index and +1 for next line + vim.fn.cursor(end_row + 1 + (add_empty_line and 1 or 0), 0) -- +1 for next line vim.cmd([[startinsert!]]) end end diff --git a/queries/org/highlights.scm b/queries/org/highlights.scm index 773480fa4..b83605308 100644 --- a/queries/org/highlights.scm +++ b/queries/org/highlights.scm @@ -9,10 +9,9 @@ (headline (stars) @stars (#eq? @stars "*******")) @OrgTSHeadlineLevel7 (headline (stars) @stars (#eq? @stars "********")) @OrgTSHeadlineLevel8 (bullet) @OrgTSBullet - (checkbox) @OrgTSCheckbox - ((checkbox) @check (#eq? @check "\[-\]")) @OrgTSCheckboxHalfChecked - ((checkbox) @check (#eq? @check "\[ \]")) @OrgTSCheckboxUnchecked - ((checkbox) @check (#match? @check "\[[xX]\]")) @OrgTSCheckboxChecked +(listitem . (bullet) . (paragraph . (expr "[" "str" @OrgCheckDone "]") @OrgTSCheckboxChecked (#match? @OrgTSCheckboxChecked "\[[xX]\]"))) +(listitem . (bullet) . (paragraph . (expr "[" "-" @OrgCheckInProgress "]") @OrgTSCheckboxHalfChecked (#eq? @OrgTSCheckboxHalfChecked "[-]"))) +(listitem . (bullet) . (paragraph . ((expr "[") @OrgTSCheckbox.left (#eq? @OrgTSCheckbox.left "[") . (expr "]") @OrgTSCheckbox.right (#eq? @OrgTSCheckbox.right "]")))) (property_drawer) @OrgTSPropertyDrawer (drawer) @OrgTSDrawer (tag) @OrgTSTag