Skip to content

Conversation

@mstojanovic
Copy link
Contributor

Code is commented since the math is a bit tricky and not intuitive. And
vimscript doesn't like floating point calculations

Code is commented since the math is a bit tricky and not intuitive. And
vimscript doesn't like floating point calculations
@dkarter
Copy link
Member

dkarter commented May 6, 2021

Thanks for the PR @mstojanovic!

Would be good to add a snapshot test to spec/checkboxes_spec.rb that would confirm what would happen at each step, something along these lines:

  it 'toggle a checkbox step wise for 6 bullets' do
    filename = "#{SecureRandom.hex(6)}.txt"
    write_file(filename, <<-TEXT)
      # Hello there
      - [ ] top bullet
        - [ ] first bullet
        - [ ] second bullet
        - [ ] third bullet
        - [ ] fourth bullet
        - [ ] fifth bullet
        - [ ] sixth bullet
    TEXT

    vim.edit filename
    vim.command "let g:bullets_checkbox_markers=' .:oOX'"
    vim.normal '2j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 1/6 = 16%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [.] top bullet
        - [X] first bullet
        - [ ] second bullet
        - [ ] third bullet
        - [ ] fourth bullet
        - [ ] fifth bullet
        - [ ] sixth bullet

    TEXT

    vim.normal 'j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 2/6 = 33%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [:] top bullet
        - [X] first bullet
        - [X] second bullet
        - [ ] third bullet
        - [ ] fourth bullet
        - [ ] fifth bullet
        - [ ] sixth bullet

    TEXT

    vim.normal 'j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 3/6 = 50%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [:] top bullet
        - [X] first bullet
        - [X] second bullet
        - [X] third bullet
        - [ ] fourth bullet
        - [ ] fifth bullet
        - [ ] sixth bullet

    TEXT

    vim.normal 'j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 4/6 = 66%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [o] top bullet
        - [X] first bullet
        - [X] second bullet
        - [X] third bullet
        - [X] fourth bullet
        - [ ] fifth bullet
        - [ ] sixth bullet

    TEXT

    vim.normal 'j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 5/6 = 83%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [O] top bullet
        - [X] first bullet
        - [X] second bullet
        - [X] third bullet
        - [X] fourth bullet
        - [X] fifth bullet
        - [ ] sixth bullet

    TEXT

    vim.normal 'j'
    vim.command 'ToggleCheckbox'
    vim.write

    file_contents = IO.read(filename)

    # 6/6 = 100%
    expect(file_contents).to eq normalize_string_indent(<<-TEXT)
      # Hello there
      - [X] top bullet
        - [X] first bullet
        - [X] second bullet
        - [X] third bullet
        - [X] fourth bullet
        - [X] fifth bullet
        - [X] sixth bullet

    TEXT
  end

@mstojanovic
Copy link
Contributor Author

mstojanovic commented May 6, 2021

on it, i will do it asap just to clear one thing so that it makes more sense to all the users.
since i forked the project because i needed this feature ive noticed that the rounding doesnt really work as said.
i sad that the including border value is on the left (e.g. [25,50>) but after some usage and recalculations with this code its on the right (e.g. <25,50]). the issue is when the number_of_markers-2 == number_of_cb. and probably for some multiples k*number_of_markers-2 (honestly im too lazy to calculate now the correct formula for that).
basically my question boils down to decide what is more readable/understandable/natural (suppose 6 markers ' .:oOX')
a) right border included <50,75]

- [o] lowercase 
  - [X]
  - [X]
  - [X]
  - [ ]

b) left border included [75,100>

- [O] uppercase 
  - [X]
  - [X]
  - [X]
  - [ ]

@harshad1
Copy link
Collaborator

@mstojanovic This still merges and passes existing tests. Do you plan to add tests or should I just merge it?

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.

3 participants