mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
added DONE toggle...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f1d7dd2ff0
commit
6939f96098
@ -111,8 +111,6 @@ var blocks = {
|
|||||||
.replace(/^\s*(?<!\\)>\s+(.*)$/m, this.style(editor, elem, 'quote'))
|
.replace(/^\s*(?<!\\)>\s+(.*)$/m, this.style(editor, elem, 'quote'))
|
||||||
.replace(/^\s*(?<!\\)((\/\/|;)\s+.*)$/m, this.style(editor, elem, 'comment'))
|
.replace(/^\s*(?<!\\)((\/\/|;)\s+.*)$/m, this.style(editor, elem, 'comment'))
|
||||||
.replace(/^\s*(?<!\\)NOTE:?\s*(.*)$/m, this.style(editor, elem, 'NOTE'))
|
.replace(/^\s*(?<!\\)NOTE:?\s*(.*)$/m, this.style(editor, elem, 'NOTE'))
|
||||||
.replace(/^\s*(?<!\\)DONE\s+(.*)$/m, this.style(editor, elem, 'DONE'))
|
|
||||||
.replace(/^(.*)\s*(?<!\\)DONE\s*$/m, this.style(editor, elem, 'DONE'))
|
|
||||||
.replace(/^\s*(?<!\\)XXX\s+(.*)$/m, this.style(editor, elem, 'XXX'))
|
.replace(/^\s*(?<!\\)XXX\s+(.*)$/m, this.style(editor, elem, 'XXX'))
|
||||||
.replace(/^(.*)\s*(?<!\\)XXX$/m, this.style(editor, elem, 'XXX')) } ,
|
.replace(/^(.*)\s*(?<!\\)XXX$/m, this.style(editor, elem, 'XXX')) } ,
|
||||||
}
|
}
|
||||||
@ -202,6 +200,11 @@ var quoted = {
|
|||||||
var tasks = {
|
var tasks = {
|
||||||
__proto__: plugin,
|
__proto__: plugin,
|
||||||
|
|
||||||
|
done_patterns: [
|
||||||
|
/^\s*(?<!\\)DONE\s+(.*)$/m,
|
||||||
|
/^(.*)\s*(?<!\\)DONE\s*$/m,
|
||||||
|
],
|
||||||
|
|
||||||
updateStatus: function(editor, node){
|
updateStatus: function(editor, node){
|
||||||
node = editor.get(node)
|
node = editor.get(node)
|
||||||
if(node == null){
|
if(node == null){
|
||||||
@ -316,9 +319,36 @@ var tasks = {
|
|||||||
prevCheckbox: function(editor, node='focused', offset=-1){
|
prevCheckbox: function(editor, node='focused', offset=-1){
|
||||||
return this.nextCheckbox(editor, node, offset) },
|
return this.nextCheckbox(editor, node, offset) },
|
||||||
|
|
||||||
|
toggleDone: function(editor, elem){
|
||||||
|
var node = editor.get(elem)
|
||||||
|
if(node == null){
|
||||||
|
return }
|
||||||
|
var text = node.querySelector('.code')
|
||||||
|
var value = text.value
|
||||||
|
var s = text.selectionStart
|
||||||
|
var e = text.selectionEnd
|
||||||
|
var l = text.value.length
|
||||||
|
if(this.done_patterns
|
||||||
|
.reduce(function(res, p){
|
||||||
|
return res
|
||||||
|
|| p.test(text.value) } , false)){
|
||||||
|
for(var p of this.done_patterns){
|
||||||
|
value = value.replace(p, '$1') }
|
||||||
|
} else {
|
||||||
|
value = 'DONE ' + value }
|
||||||
|
text.value = value
|
||||||
|
text.selectionStart = s + (value.length - l)
|
||||||
|
text.selectionEnd = e + (value.length - l)
|
||||||
|
editor.update(node)
|
||||||
|
return node },
|
||||||
|
|
||||||
__setup__: function(editor){
|
__setup__: function(editor){
|
||||||
return this.updateAllStatus(editor) },
|
return this.updateAllStatus(editor) },
|
||||||
__parse__: function(text, editor, elem){
|
__parse__: function(text, editor, elem){
|
||||||
|
// handle done..
|
||||||
|
for(var p of this.done_patterns){
|
||||||
|
test = text
|
||||||
|
.replace(p, this.style(editor, elem, 'DONE')) }
|
||||||
return text
|
return text
|
||||||
// block checkboxes...
|
// block checkboxes...
|
||||||
// NOTE: these are separate as we need to align block text
|
// NOTE: these are separate as we need to align block text
|
||||||
@ -1204,22 +1234,18 @@ var Outline = {
|
|||||||
this.remove(edited)
|
this.remove(edited)
|
||||||
return } },
|
return } },
|
||||||
|
|
||||||
// select...
|
d: function(evt){
|
||||||
// XXX add:
|
// toggle done...
|
||||||
// ctrl-A
|
if(evt.ctrlKey){
|
||||||
// ctrl-D
|
evt.preventDefault()
|
||||||
|
tasks.toggleDone(this) } },
|
||||||
|
|
||||||
|
// toggle checkbox...
|
||||||
' ': function(evt){
|
' ': function(evt){
|
||||||
if(this.get('edited') != null){
|
if(this.get('edited') != null){
|
||||||
return }
|
return }
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
tasks.toggleCheckbox(this)
|
tasks.toggleCheckbox(this) },
|
||||||
/* XXX selection...
|
|
||||||
var focused = this.get()
|
|
||||||
focused.getAttribute('selected') != null ?
|
|
||||||
focused.removeAttribute('selected')
|
|
||||||
: focused.setAttribute('selected', '')
|
|
||||||
//*/
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: function(dom){
|
setup: function(dom){
|
||||||
|
|||||||
@ -170,6 +170,7 @@ var setup = function(){
|
|||||||
| c-left | prev checkbox |
|
| c-left | prev checkbox |
|
||||||
| c-right | next checkbox |
|
| c-right | next checkbox |
|
||||||
| space | toggle current checkbox |
|
| space | toggle current checkbox |
|
||||||
|
| c-d | toggle current element DONE |
|
||||||
| enter | normal mode: edit node |
|
| enter | normal mode: edit node |
|
||||||
| | edit mode: create node below |
|
| | edit mode: create node below |
|
||||||
| esc | exit edit mode |
|
| esc | exit edit mode |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user