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

fix(promo): promote/demote range + keybinds #1487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

benlubas
Copy link
Contributor

what it says on the tin. These were broken/removed a while ago. Presumably due to concealer changes but I'm not sure. Someone asked about bringing them back today, so here they are.

The re-indentation code in this module seems to struggle a little though. Not sure what's up with that.

@mtrajano
Copy link

Looks to be working fine for me. Tried indenting several nested lists with no problem, what issues did you run into re: the indentation?

@vhyrro
Copy link
Member

vhyrro commented Jun 27, 2024

@mtrajano the issue stems from e.g. paragraphs. It seems that the indentation is cumulative: with the following snippet:

* One
** Two
     content.

Doing a ranged promotion indents the paragraph twice as far:

** One
*** Two
              content.

This isn't the absolute end of the world, but would be nice to have fixed somehow 🤔

edit: wow, github rendering makes the indentation look really bad in the code block. it's less bad in a Norg buffer haha

@benlubas
Copy link
Contributor Author

@mtrajano @vhyrro

Now this behaves itself a little better. There is still one behavior that might be unexpected. If you promote:

* heading
  Normal text

Normal text is correctly indented. But if you promote:

normal text
- list item

Then "normal text" is indented, while "list item" is promoted. However, this case:

- list

new paragraph
- new list

"new paragraph" is not indented.


I think this behavior is fine. It allows visual >/< to still work like normal in norg documents when you don't highlight anything promote-able. And if you only highlight the things you want to promote without extra paragraphs, there's no problem with it.

@mtrajano
Copy link

Changes make sense to make, there's just a random print statement there

Comment on lines 171 to 172
local current_visual_indent = vim.fn.indent(row + 1)
local new_indent = math.max(0, current_visual_indent + n_space_diff)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels internal to the indent module. Shouldn't have to pass it an indent, just a bufnr and a range/line number and it should be able to figure it out

@@ -28,17 +28,21 @@ local neorg = require("neorg.core")
local modules = neorg.modules

local module = modules.create("core.promo")
local indent
Copy link

@mtrajano mtrajano Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be part of module.private, not sure what the convention around this is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this convention, vhyrro and I have gone back and forth on this in the past as well.

---@param buffer number
---@param start_row number 0 based
---@param new_indent number
buffer_set_line_indent = function(buffer, start_row, new_indent)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename to reindent_line just to be consistent with the above, and rename the start_row to line

@vhyrro
Copy link
Member

vhyrro commented Jun 28, 2024

@benlubas the new behaviour is much better than what we had previously, so that sounds good enough for the time being. Running out of time today, but I'll revisit this PR tomorrow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants