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

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

Closed
kvalv opened this issue Jun 30, 2021 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@kvalv
Copy link

kvalv commented Jun 30, 2021

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

simplescreenrecorder-.37.mp4

System information:

  • OS: linux
  • Neovim version/commit: Nvim: NVIM v0.5.0-dev+1449-gbdf3df402
  • orgmode commit: 6b99d66

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 kvalv added the bug Something isn't working label Jun 30, 2021
@kvalv
Copy link
Author

kvalv commented Jun 30, 2021

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

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

kvalv commented Jun 30, 2021

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

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

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

kvalv commented Jun 30, 2021

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.

simplescreenrecorder-.39.mp4

@kristijanhusak
Copy link
Member

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

kvalv commented Jun 30, 2021

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.

@kvalv kvalv closed this as completed Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants