antonk52 / markdowny.nvim

Markdown like keymaps for toggling text formatting
73 stars 7 forks source link

Refactor & Support code block with `<C-e>` #7

Closed ful1e5 closed 1 year ago

ful1e5 commented 1 year ago

This refactor involves several modifications to the codebase aimed at enhancing code quality and readability. Key changes include the addition of Lua documentation to functions, the renaming of internal variables and functions, and the modification of the way position variables are accessed. The surrounder function has also been heavily refactored and renamed to __toggle_surround to reduce the number of lines of code and improve readability.

The codebase also includes a new feature that supports formatting code blocks using the <C-e> key combination (fixes #4). The feature consists of an implementation of a code function for handling single-line and multi-line delimiters using a table-based approach, which allows for more flexible handling of parameters. Additionally, the __update_start_selection_mark utility function has been introduced to facilitate updating the starting position of the selection mark when using optional parameters such as adding surround to multiple lines of code.

Further details on these changes can be found in individual commits.

https://user-images.githubusercontent.com/24286590/215761705-97d2156e-877d-4413-8e38-05b3bc78d0a8.mp4

antonk52 commented 1 year ago

Nice work, the only change I want to ask is to make is when an entire line is selected to add the triple backtick to new lines surrounding the selected line instead of on the same line. Personally I haven't came across such usage in my career. Though if you think it is a useful case, maybe we should have an option to enable single_line_code_block. What do you think?

ful1e5 commented 1 year ago

I completely rewrote the plugin and deprecated the inline_code() function. I have added newline and single-line surroundings like you asked, considering #1.

If you want to disregard older commits, I am happy to open a new Pull Request with only the latest commits.

ful1e5 commented 1 year ago

Closing PR; because #7.