jakewvincent / mkdnflow.nvim

Fluent navigation and management of markdown notebooks
GNU General Public License v3.0
684 stars 41 forks source link

Bug: Crash when pressing <CR> in a table in normal mode #237

Closed anotherhadi closed 2 months ago

anotherhadi commented 3 months ago

When pressing (MkdnEnter) on a empty cell in a table in normal mode my nvim session crash.

jakewvincent commented 2 months ago

I need some more information in order to troubleshoot, as I can't reproduce this on my end. What's your config (or are you using the default)? Is it happening in any empty cell of a table? Can you share the text of a table where you're getting this behavior (not a screenshot).

anotherhadi commented 2 months ago

Steps:

I'm on NixOS (with nixvim), so maybe the defaults are different, but here's my config:

{
  programs.nixvim.plugins = {
    mkdnflow = {
      enable = true;
      mappings = {

        # Main
        MkdnEnter = {
          key = "<CR>";
          modes = [ "n" "v" "i" ];
        };

        # Links
        MkdnCreateLink = false;
        MkdnCreateLinkFromClipboard = {
          key = "<leader>lc";
          modes = [ "n" "v" ];
        };
        MkdnDestroyLink = {
          key = "<leader>dl";
          modes = "n";
        };
        MkdnFollowLink = false;
        MkdnNextLink = {
          key = "<Tab>";
          modes = "n";
        };
        MkdnYankAnchorLink = {
          key = "ya";
          modes = "n";
        };
        MkdnYankFileAnchorLink = {
          key = "yfa";
          modes = "n";
        };
        MkdnPrevLink = {
          key = "<S-Tab>";
          modes = "n";
        };

        MkdnDecreaseHeading = {
          key = "-";
          modes = "n";
        };
        MkdnExtendList = false;
        MkdnFoldSection = {
          key = "<leader>ff";
          modes = "n";
        };
        MkdnUnfoldSection = {
          key = "<leader>fu";
          modes = "n";
        };
        MkdnGoBack = {
          key = "<BS>";
          modes = "n";
        };
        MkdnGoForward = {
          key = "<Del>";
          modes = "n";
        };
        MkdnIncreaseHeading = {
          key = "+";
          modes = "n";
        };
        MkdnMoveSource = {
          key = "<F2>";
          modes = "n";
        };
        MkdnNewListItem = false;
        MkdnNewListItemAboveInsert = {
          key = "O";
          modes = "n";
        };
        MkdnNewListItemBelowInsert = {
          key = "o";
          modes = "n";
        };
        MkdnNextHeading = {
          key = "]]";
          modes = "n";
        };
        MkdnPrevHeading = {
          key = "[[";
          modes = "n";
        };
        MkdnSTab = false;
        MkdnTab = false;
        MkdnTableFormat = {
          key = "<leader>ft";
          modes = "n";
        };
        MkdnTableNewColAfter = {
          key = "<leader>ic";
          modes = "n";
        };
        MkdnTableNewColBefore = {
          key = "<leader>iC";
          modes = "n";
        };
        MkdnTableNewRowAbove = {
          key = "<leader>iR";
          modes = "n";
        };
        MkdnTableNewRowBelow = {
          key = "<leader>ir";
          modes = "n";
        };
        MkdnTableNextCell = {
          key = "<S-Tab>";
          modes = "i";
        };
        MkdnTableNextRow = false;
        MkdnTablePrevCell = {
          key = "<M-Tab>";
          modes = "i";
        };
        MkdnTablePrevRow = {
          key = "<M-CR>";
          modes = "i";
        };
        MkdnToggleToDo = {
          key = "<C-Space>";
          modes = [ "n" "v" ];
        };
        MkdnUpdateNumbering = {
          key = "<leader>nn";
          modes = "n";
        };
      };
    };
  };
}
jakewvincent commented 2 months ago

Thanks for the info! I'll get back to you soon, hopefully tomorrow.

jakewvincent commented 2 months ago

Ok, I think I'd like to take a look at the config as it is interpreted by the plugin, just in case there's some kind of issue mapping the Nix file to Lua. Can you paste the output of vim.print(require('mkdnflow').config) here for me?

anotherhadi commented 2 months ago

Sure, here's it:

{
  bib = {
    find_in_root = true
  },
  create_dirs = true,
  cursor = {},
  filetypes = {
    markdown = true,
    md = true,
    rmd = true
  },
  foldtext = {
    fill_chars = {
      item_separator = " · ",
      left_edge = "⢾⣿⣿",
      left_inside = " ⣹",
      middle = "⣿",
      right_edge = "⣿⣿⡷",
      right_inside = "⣏ ",
      section_separator = " ⣹⣿⣏ "
    },
    line_count = true,
    line_percentage = true,
    object_count = true,
    object_count_icon_set = "emoji",
    object_count_opts = <function 1>,
    title_transformer = <function 2>,
    word_count = false
  },
  links = {
    conceal = false,
    context = 0,
    create_on_follow_failure = true,
    name_is_source = false,
    style = "markdown",
    transform_explicit = <function 3>,
    transform_implicit = false
  },
  mappings = {
    MkdnCreateLink = false,
    MkdnCreateLinkFromClipboard = { { "n", "v" }, "<leader>lc" },
    MkdnDecreaseHeading = { "n", "-" },
    MkdnDestroyLink = { "n", "<leader>dl" },
    MkdnEnter = { { "n", "v", "i" }, "<CR>" },
    MkdnExtendList = false,
    MkdnFoldSection = { "n", "<leader>ff" },
    MkdnFollowLink = false,
    MkdnGoBack = { "n", "<BS>" },
    MkdnGoForward = { "n", "<Del>" },
    MkdnIncreaseHeading = { "n", "+" },
    MkdnMoveSource = { "n", "<F2>" },
    MkdnNewListItem = false,
    MkdnNewListItemAboveInsert = { "n", "O" },
    MkdnNewListItemBelowInsert = { "n", "o" },
    MkdnNextHeading = { "n", "]]" },
    MkdnNextLink = { "n", "<Tab>" },
    MkdnPrevHeading = { "n", "[[" },
    MkdnPrevLink = { "n", "<S-Tab>" },
    MkdnSTab = false,
    MkdnTab = false,
    MkdnTableFormat = { "n", "<leader>ft" },
    MkdnTableNewColAfter = { "n", "<leader>ic" },
    MkdnTableNewColBefore = { "n", "<leader>iC" },
    MkdnTableNewRowAbove = { "n", "<leader>iR" },
    MkdnTableNewRowBelow = { "n", "<leader>ir" },
    MkdnTableNextCell = { "i", "<S-Tab>" },
    MkdnTableNextRow = false,
    MkdnTablePrevCell = { "i", "<M-Tab>" },
    MkdnTablePrevRow = { "i", "<M-CR>" },
    MkdnTagSpan = { "v", "<M-CR>" },
    MkdnToggleToDo = { { "n", "v" }, "<C-Space>" },
    MkdnUnfoldSection = { "n", "<leader>fu" },
    MkdnUpdateNumbering = { "n", "<leader>nn" },
    MkdnYankAnchorLink = { "n", "ya" },
    MkdnYankFileAnchorLink = { "n", "yfa" }
  },
  modules = {
    bib = true,
    buffers = true,
    cmp = false,
    conceal = true,
    cursor = true,
    folds = true,
    foldtext = true,
    links = true,
    lists = true,
    maps = true,
    paths = true,
    tables = true,
    yaml = false
  },
  new_file_template = {
    placeholders = {
      after = {},
      before = {
        date = "os_date",
        title = "link_title"
      }
    },
    template = "# {{title}}",
    use_template = false
  },
  perspective = {
    fallback = "current",
    nvim_wd_heel = false,
    priority = "first",
    root_tell = false,
    update = true
  },
  silent = false,
  tables = {
    auto_extend_cols = false,
    auto_extend_rows = false,
    format_on_move = true,
    style = {
      cell_padding = 1,
      mimic_alignment = true,
      outer_pipes = true,
      separator_padding = 1
    },
    trim_whitespace = true
  },
  to_do = {
    complete = "X",
    in_progress = "-",
    not_started = " ",
    symbols = { " ", "-", "X" },
    update_parents = true
  },
  wrap = false,
  yaml = {
    bib = {
      override = false
    }
  }
}
jakewvincent commented 2 months ago

Hi @anotherhadi, this should be fixed now in the latest version. Although it won't freeze up now, I suspect the behavior you're looking for in this case is to go to the same column in the next row in the table when hitting enter in normal mode. Is that right? With the current version of MkdnEnter, that will only happen if you're in insert mode. In normal mode, MkdnEnter will first try to open or close a folded section (if there is one under the cursor), then it will try to follow a link (if there is one under the cursor), and if neither of those conditions are met, it will try to create a link. So what will happen in your example case (and with your config) is MkdnEnter will try to create a link from a part of the table.

A workaround for the attempted link creation is to set links.create_on_follow_failure to false (see the links config descriptions in the readme). If you're hoping for the cursor to move to the same column in the next row in such cases, some additional work will be needed for MkdnEnter (and you can submit a separate issue/feature request for that).

Let me know if you're still experiencing the issue after updating, and let me know if you have any questions. Thanks for reporting the issue!

anotherhadi commented 2 months ago

Hi, thanks for the quick answer! I'm using nixvim so I'll wait for them to update the plugin in their repo!