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

Feature/858/checkboxtoggle #861

Merged
merged 17 commits into from
Aug 5, 2022
Merged

Feature/858/checkboxtoggle #861

merged 17 commits into from
Aug 5, 2022

Conversation

newhinton
Copy link
Contributor

@newhinton newhinton commented May 22, 2022

fixes #858

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Copy link
Member

@korelstar korelstar left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! I really like it! Here are some remarks for improving it:

  • Changing a checkbox only works once for me. After that, any other change is done visually, but not in the note. I have to reload to proceed.
  • Please respect the read-only attribute. The checkboxes should not be editable if read-only mode is active.
  • Could you please change the mouse cursor? Currently it is text selection, but I think it should be the default pointer.
  • Would it be possible to use the same checkbox design like in edit mode?

package-lock.json Outdated Show resolved Hide resolved
src/components/EditorMarkdownIt.vue Outdated Show resolved Hide resolved
@newhinton newhinton changed the title Feature/858/checkboxtoggle Draft: Feature/858/checkboxtoggle May 29, 2022
@newhinton newhinton changed the title Draft: Feature/858/checkboxtoggle Feature/858/checkboxtoggle May 29, 2022
@newhinton newhinton marked this pull request as draft May 29, 2022 20:27
@newhinton
Copy link
Contributor Author

newhinton commented May 30, 2022

Changing a checkbox only works once for me. After that, any other change is done visually, but not in the note. I have to reload to proceed.

That is interesting. I can reproduce, however, the onEdit call does take the correct content, but it seems it does not save it. I have to figure out why. I was wrong, that was the editor not the preview

Would it be possible to use the same checkbox design like in edit mode?

Yes, but no. :D I have already changed the checkbox design in #790 to use rounded corners, so that the editor matches the preview. If you dont object, i would like to do it that way:

Editor:
grafik

Preview:
grafik
(the editor has a slightly smaller border)

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
@newhinton
Copy link
Contributor Author

How do i test the read-only attribute? I have passed it just like the editor so it 'should' be fine, but i have never encountered a read only note. Are those shared from other people?

use regex for checking if todo

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
@newhinton
Copy link
Contributor Author

newhinton commented May 31, 2022

So, i fixed the single click only bug. Sadly i had to introduce a timeout function so that the v-html can render and the new content is actually found with the checkboxes. If you have a better idea please tell me.

Also i found a very strange bug, but i think this is the issue with MarkdownIT.

 - [x] test
 - [x] test2
 [ ] test
 
 
 test

This note will have 2 checkboxes, as expected, but the label of the second one extends to a second line. Can you confirm this behaviour on your end?

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
@newhinton newhinton marked this pull request as ready for review May 31, 2022 08:04
Comment on lines 90 to 96
if (target.checked) {
returnValue = returnValue.replace('[ ]', '[x]')
returnValue = returnValue.replace('[\u00A0]', '[x]')
} else {
returnValue = returnValue.replace('[x]', '[ ]')
returnValue = returnValue.replace('[X]', '[ ]')
}
Copy link
Member

Choose a reason for hiding this comment

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

This does not work correctly if there is a [ ] or [x] in the item's text, e.g. - [x] this is an example [x] with checkbox. In this case, the text is also changed. In order to fix this, it must be assured, that only a single replace is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as i know the .replace() function only replaces the first occurence, when no regex is used. Even if a regex is applied, when the global-flag is missing it will also only chamge the first occurence. So this should be fine, did your test yield different results?

Copy link
Member

Choose a reason for hiding this comment

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

Please try my example. It doesn't work correctly. But I did not found out why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works just fine for me, have you cleared the cache? (I had problems when the developer console wasnt open, it was using some broken hybrid version from cache)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only has the behaviour you describe if we have both an uppercase and a lowercase X in the line. I will have to fix this particular issue though.

Copy link
Member

Choose a reason for hiding this comment

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

I've found out that it happens on sub-items only, see the following example:

- [ ] check [ ] box (works)
 - [ ] sub check [ ] box (does not work)
- [ ] check [ ] box (works)

Copy link
Contributor Author

@newhinton newhinton Jul 10, 2022

Choose a reason for hiding this comment

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

  • check [ ] box (works)
  • sub check [ ] box (does not work)
  • check [ ] box (works)

I also cannot reproduce this. Is the sub-element supposed to be indented? Because on my build it behaves identical to the other two (including the checkbox behaviour)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the second item should be indented. See this screenshot:

Screenshot

newhinton and others added 2 commits July 10, 2022 17:54
Co-authored-by: korelstar <korelstar@users.noreply.github.com>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
@korelstar
Copy link
Member

So, i fixed the single click only bug. Sadly i had to introduce a timeout function so that the v-html can render and the new content is actually found with the checkboxes. If you have a better idea please tell me.

I think it's fine, for now.

Also i found a very strange bug, but i think this is the issue with MarkdownIT.

 - [x] test
 - [x] test2
 [ ] test
 
 
 test

This note will have 2 checkboxes, as expected, but the label of the second one extends to a second line. Can you confirm this behaviour on your end?

Yes, I can reproduce this. But I agree that this is caused by markdown-it.

Copy link
Member

@korelstar korelstar left a comment

Choose a reason for hiding this comment

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

How do i test the read-only attribute? I have passed it just like the editor so it 'should' be fine, but i have never encountered a read only note. Are those shared from other people?

Yes, that's the typical use case. But you could test this also by manually removing write permission to the note's file directly on the file system.

I've added a code change suggestion in order to improve this case: The checkboxes should be disabled if and only if the note is read-only.

src/components/EditorMarkdownIt.vue Outdated Show resolved Hide resolved
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
@korelstar
Copy link
Member

@newhinton What's the state of this PR? As far as I can see, there is only one bug left: the issue with the sub-items (see #861 (comment)). Any ideas on how to fix this?

@korelstar
Copy link
Member

@newhinton What's the state of this PR? As far as I can see, there is only one bug left: the issue with the sub-items (see #861 (comment)). Any ideas on how to fix this?

Okay, I found a fix. It was because clicking on a sub-item triggers an event for the sub-item AND for the parent item. I had to stop event propagation.

@korelstar korelstar merged commit dc3672f into master Aug 5, 2022
@korelstar korelstar deleted the feature/858/checkboxtoggle branch August 5, 2022 21:19
@korelstar korelstar added this to the 4.5.0 milestone Aug 5, 2022
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.

Allow Checkbox to be toggled in viewmode
2 participants