nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3k stars 131 forks source link

<C-A> to increase date will increase the year if cursor is not on the date #19

Closed kvalv closed 3 years ago

kvalv commented 3 years ago

Hey, this is a really nice project and I'm happy to see such active development on this. It already looks promising!

Describe the bug Using <C-a> when the cursor is not on the date will increment the year, and thereafter it'll work properly.

To Reproduce Steps to reproduce the behavior:

  1. Write some text and then write :now: and exit insert mode.
  2. Go to the start of line (e.g. by typing 0 (zero) )
  3. Type <C-a>
  4. The year has increased to 2022. Next time I type <C-a> the day increases, as expected.

Expected behavior The date should increase by one day when I type <C-a>, even if the cursor is not on the date object.

Screenshots

https://user-images.githubusercontent.com/9867901/123950229-be44ab00-d9a3-11eb-95b0-9049920026c8.mp4

System information:

Additional context <C-a> normally finds the closest number and increase it, so it makes sense that the first <C-a> increase the year (that's vim builtin behaviour). Subsequently the cursor is on the date object, and orgmode <C-a> functionality takes precedence and increase the day. However, I consider this a bug because the expected behaviour is that <C-a> should "do the right thing" and increase the date immediately.

I guess also <C-x> have the same issue.

kvalv commented 3 years ago

If you think it's worth fixing, I could actually try to fix it myself. I don't have much experience with lua, but this doesn't seem to be too hard to fix.

kristijanhusak commented 3 years ago

Idea is to have / increment/decrement date by one day when used within date context. Anything outside of it fallback to the default behavior.

As you said, Vim automatically finds first number and increases it. I don't think there's a way to prevent it from doing that.

Workaround is to bind date increment/decrement to another mapping, for example +/-:

require('orgmode').setup({
  mappings = {
    org = {
      org_increase_date = '+',
      org_decrease_date = '+'
    }
  }
})

That way / will work by default everywhere.

kvalv commented 3 years ago

Workaround is to bind date increment/decrement to another mapping, for example +/-:

I tried what you suggested, but it seemed to give the same behaviour as <C-a> / <C-x>, probably because the fallback is sent to nvim here: https://github.com/kristijanhusak/orgmode.nvim/blob/master/lua/orgmode/org/mappings.lua#L118

So I guess what I'm asking for is that <C-a> will first move to the date context (similar to how <C-a> is moving to the closest number) and then increase the date by one. Alternatively, it does not do anything if it's not on a date context. I think the current behaviour is not so intuitive, even though it makes sense by how vim's <C-a> and org-mode's <C-a> work

kristijanhusak commented 3 years ago

Oh, right, I need to fix that fallback to fallback to the defined mapping.

We could handle it by jumping to next number manually and then re-checking if it's date or not. Thanks for suggestion, I'll try to fix it.

kristijanhusak commented 3 years ago

@kvalv I pushed a fix for this.

  1. Different mappings are now properly falling back to the ones defined
  2. / Behaves as you suggested. It should properly jump to the date and increase it by a day.

Let me know if it works as expected.

kvalv commented 3 years ago

Hey, nice to hear you worked on this!

  1. OK, so the way I understood it, if the cursor is on the beginning of the line and I hit <C-a> it should move to the next date object and increase it by 1 day. On the video, if I hit do that, nothing happens. (which is still much better than increasing the year)

  2. Perhaps an unexpected side-effect of the change is that if I now type <C-a> without next dates, it moves to the nearest number (in this case 2), which I think also is not intended.

https://user-images.githubusercontent.com/9867901/124020825-18b52a00-d9eb-11eb-92bd-87ea5cccb691.mp4

kristijanhusak commented 3 years ago

Do you have default mappings set for this? It's not behaving same for you like it is for me. Here's gif how it works for me:

date-increase

kvalv commented 3 years ago

Hey, yes you are right about that. I added this to the config:

 mappings = {
    org = {
      org_increase_date = '+',
      org_decrease_date = '+'
    }

and after removing that mapping it works as expected. Really nice, thank you very much! I guess this can be closed then.