-
Notifications
You must be signed in to change notification settings - Fork 157
Feature/858/checkboxtoggle #861
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
Changes from 13 commits
89a8f60
eb5a779
67808dd
b4fffa5
fc134ed
848598b
f6fd354
ceb2d29
131d1ef
d365091
21dd736
8d5c4d3
73824cc
40f56ce
22b59f2
a14f337
dd810ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,10 @@ export default { | |
| type: String, | ||
| required: true, | ||
| }, | ||
| readonly: { | ||
| type: Boolean, | ||
| required: true, | ||
| }, | ||
| noteid: { | ||
| type: String, | ||
| required: true, | ||
|
|
@@ -29,7 +33,7 @@ export default { | |
| }) | ||
|
|
||
| md.use(require('markdown-it-task-checkbox'), { | ||
| disabled: true, | ||
| disabled: false, | ||
| liClass: 'task-list-item', | ||
| }) | ||
|
|
||
|
|
@@ -51,7 +55,49 @@ export default { | |
| methods: { | ||
| onUpdate() { | ||
| this.html = this.md.render(this.value) | ||
| setTimeout(() => this.prepareOnChangeListener(), 100) | ||
| }, | ||
|
|
||
| prepareOnChangeListener() { | ||
| if (this.readonly) { | ||
| return | ||
| } | ||
| const items = document.getElementsByClassName('task-list-item') | ||
| for (let i = 0; i < items.length; ++i) { | ||
| items[i].removeEventListener('click', this.setListener) | ||
| items[i].addEventListener('click', this.setListener) | ||
| } | ||
| }, | ||
|
|
||
| setListener(item) { | ||
| let idOfCheckbox = 0 | ||
| const markdownLines = this.value.split('\n') | ||
| markdownLines.forEach((line, i) => { | ||
| // Regex Source: https://github.com/linsir/markdown-it-task-checkbox/blob/master/index.js#L121 | ||
| // plus the '- '-string. | ||
| if (/^-\s+\[[xX \u00A0]\][ \u00A0]/.test(line.trim())) { | ||
| markdownLines[i] = this.checkLine(line, i, idOfCheckbox, item.target) | ||
| idOfCheckbox++ | ||
| } | ||
| }) | ||
|
|
||
| this.$emit('input', markdownLines.join('\n')) | ||
| }, | ||
|
|
||
| checkLine(line, index, id, target) { | ||
| let returnValue = line | ||
| if ('cbx_' + id === target.id) { | ||
| if (target.checked) { | ||
| returnValue = returnValue.replace('[ ]', '[x]') | ||
| returnValue = returnValue.replace('[\u00A0]', '[x]') | ||
| } else { | ||
| // matches [x] or [X], to prevent two occurences of uppercase and lowercase X to be replaced | ||
| returnValue = returnValue.replace(/\[(x|X)\]/, '[ ]') | ||
| } | ||
|
Comment on lines
+90
to
+95
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not work correctly if there is a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| return returnValue | ||
| }, | ||
|
|
||
| setImageRule(id) { | ||
| // https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer | ||
| // Remember old renderer, if overridden, or proxy to default renderer | ||
|
|
@@ -181,6 +227,7 @@ export default { | |
| list-style-type: none; | ||
| input { | ||
| min-height: initial !important; | ||
| cursor: pointer; | ||
| } | ||
| label { | ||
| cursor: default; | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.