Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anotherhadi opened this issue Jul 5, 2024 · 7 comments
Closed

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

anotherhadi opened this issue Jul 5, 2024 · 7 comments
Assignees
Labels
bug Something isn't working reproduced Issue was reproduced

Comments

@anotherhadi
Copy link

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

@jakewvincent
Copy link
Owner

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).

@jakewvincent jakewvincent self-assigned this Jul 8, 2024
@jakewvincent jakewvincent added the needs info Needs more information from the issue author label Jul 8, 2024
@anotherhadi
Copy link
Author

Steps:

  • Open a new markdown file
  • Create a 2x2 empty table using MkdnTable 2 2
  • Going to the middle of any cell
  • Press enter
  • Crash

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
Copy link
Owner

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

@jakewvincent
Copy link
Owner

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
Copy link
Author

anotherhadi commented Jul 10, 2024

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 jakewvincent added reproduced Issue was reproduced and removed needs info Needs more information from the issue author labels Jul 10, 2024
@jakewvincent
Copy link
Owner

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!

@jakewvincent jakewvincent added the bug Something isn't working label Jul 10, 2024
@jakewvincent jakewvincent changed the title Nvim crash when pressing <CR> on a table Bug: Crash when pressing <CR> in a table in normal mode Jul 10, 2024
@anotherhadi
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced Issue was reproduced
Projects
None yet
Development

No branches or pull requests

2 participants