mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
made block status toggle more flexible...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e938bbc5aa
commit
9a3e96cf09
@ -489,13 +489,17 @@ editor .outline .block:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------- Done ---*/
|
/*-------------------------------------------------------- Status ---*/
|
||||||
|
|
||||||
.editor .outline .block.DONE>.view {
|
.editor .outline .block.DONE>.view {
|
||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.editor .outline .block.REJECT>.view {
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------- Highlightes ---*/
|
/*--------------------------------------------------- Highlightes ---*/
|
||||||
|
|
||||||
|
|||||||
@ -273,10 +273,26 @@ var quoted = {
|
|||||||
var tasks = {
|
var tasks = {
|
||||||
__proto__: plugin,
|
__proto__: plugin,
|
||||||
|
|
||||||
done_patterns: [
|
status: [
|
||||||
/^\s*(?<!\\)DONE\s+(.*)$/m,
|
'DONE',
|
||||||
/^(.*)\s*(?<!\\)DONE\s*$/m,
|
'REJECT',
|
||||||
],
|
],
|
||||||
|
// format:
|
||||||
|
// [
|
||||||
|
// <status>: <pattern>,
|
||||||
|
// ...
|
||||||
|
// ]
|
||||||
|
__status_patterns: undefined,
|
||||||
|
__status_pattern_tpl: `^(?:\\s*(?<!\\\\)$STATUS:?\\s+(.*)$|(.*)\\s+(?<!\\\\)$STATUS\\s*)$`,
|
||||||
|
get status_patterns(){
|
||||||
|
var that = this
|
||||||
|
return (this.__status_patterns
|
||||||
|
??= this.status
|
||||||
|
.reduce(function(res, status){
|
||||||
|
res[status] = new RegExp(
|
||||||
|
that.__status_pattern_tpl
|
||||||
|
.replace(/\$STATUS/g, status), 'm')
|
||||||
|
return res }, {})) },
|
||||||
|
|
||||||
// State...
|
// State...
|
||||||
updateStatus: function(editor, node){
|
updateStatus: function(editor, node){
|
||||||
@ -399,8 +415,8 @@ var tasks = {
|
|||||||
return node },
|
return node },
|
||||||
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) },
|
||||||
// DONE...
|
// Status...
|
||||||
toggleDone: function(editor, elem){
|
toggleStatus: function(editor, elem, status='next', patterns=this.status_patterns){
|
||||||
var node = editor.get(elem)
|
var node = editor.get(elem)
|
||||||
if(node == null){
|
if(node == null){
|
||||||
return }
|
return }
|
||||||
@ -410,14 +426,29 @@ var tasks = {
|
|||||||
var s = text.selectionStart
|
var s = text.selectionStart
|
||||||
var e = text.selectionEnd
|
var e = text.selectionEnd
|
||||||
var l = text.value.length
|
var l = text.value.length
|
||||||
if(this.done_patterns
|
|
||||||
.reduce(function(res, p){
|
var p = Object.entries(patterns)
|
||||||
return res
|
for(var i=0; i<p.length; i++){
|
||||||
|| p.test(text.value) } , false)){
|
var [name, pattern] = p[i]
|
||||||
for(var p of this.done_patterns){
|
if(pattern.test(value)){
|
||||||
value = value.replace(p, '$1') }
|
value = value.replace(pattern, '$1')
|
||||||
} else {
|
if(status != 'off'){
|
||||||
value = 'DONE ' + value }
|
break } } }
|
||||||
|
if(status != 'off'){
|
||||||
|
// toggle specific status...
|
||||||
|
if(status != 'next'){
|
||||||
|
if(i == p.length
|
||||||
|
|| name != status){
|
||||||
|
value = status +' '+ value }
|
||||||
|
// next...
|
||||||
|
} else if(i != p.length-1){
|
||||||
|
// set next...
|
||||||
|
if(i+1 in p){
|
||||||
|
value = p[i+1][0] +' '+ value
|
||||||
|
// set first...
|
||||||
|
} else {
|
||||||
|
value = p[0][0] +' '+ value } } }
|
||||||
|
|
||||||
text.value = value
|
text.value = value
|
||||||
text.selectionStart = s + (value.length - l)
|
text.selectionStart = s + (value.length - l)
|
||||||
text.selectionEnd = e + (value.length - l)
|
text.selectionEnd = e + (value.length - l)
|
||||||
@ -428,15 +459,23 @@ var tasks = {
|
|||||||
[editor.path(node),
|
[editor.path(node),
|
||||||
data])
|
data])
|
||||||
return node },
|
return node },
|
||||||
|
toggleDone: function(editor, elem){
|
||||||
|
return this.toggleStatus(editor, elem, 'DONE') },
|
||||||
|
toggleReject: function(editor, elem){
|
||||||
|
return this.toggleStatus(editor, elem, 'REJECT') },
|
||||||
|
|
||||||
__setup__: function(editor){
|
__setup__: function(editor){
|
||||||
return this.updateAllStatus(editor) },
|
return this.updateAllStatus(editor) },
|
||||||
__pre_parse__: function(text, editor, elem){
|
__pre_parse__: function(text, editor, elem){
|
||||||
// handle done..
|
// handle done..
|
||||||
var handler = this.style(editor, elem, 'DONE')
|
var done = this.style(editor, elem, 'DONE')
|
||||||
for(var p of this.done_patterns){
|
var reject = this.style(editor, elem, 'REJECT')
|
||||||
|
for(var [n, p] of Object.entries(this.status_patterns)){
|
||||||
text = text
|
text = text
|
||||||
.replace(p, handler) }
|
.replace(p,
|
||||||
|
n == 'DONE' ?
|
||||||
|
done
|
||||||
|
: reject) }
|
||||||
return text },
|
return text },
|
||||||
__update_checkboxes_timeout: undefined,
|
__update_checkboxes_timeout: undefined,
|
||||||
__parse__: function(text, editor, elem){
|
__parse__: function(text, editor, elem){
|
||||||
@ -1892,10 +1931,18 @@ var Outline = {
|
|||||||
this.remove(edited)
|
this.remove(edited)
|
||||||
return } },
|
return } },
|
||||||
|
|
||||||
|
a_s: function(evt){
|
||||||
|
// toggle done...
|
||||||
|
evt.preventDefault()
|
||||||
|
tasks.toggleStatus(this) },
|
||||||
a_x: function(evt){
|
a_x: function(evt){
|
||||||
// toggle done...
|
// toggle done...
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
tasks.toggleDone(this) },
|
tasks.toggleDone(this) },
|
||||||
|
a_r: function(evt){
|
||||||
|
// toggle done...
|
||||||
|
evt.preventDefault()
|
||||||
|
tasks.toggleReject(this) },
|
||||||
|
|
||||||
// selection...
|
// selection...
|
||||||
// XXX need more work...
|
// XXX need more work...
|
||||||
|
|||||||
@ -244,8 +244,10 @@ var setup = function(){
|
|||||||
| s-right | expand node |
|
| s-right | expand node |
|
||||||
| c-left | prev checkbox |
|
| c-left | prev checkbox |
|
||||||
| c-right | next checkbox |
|
| c-right | next checkbox |
|
||||||
| space | toggle current checkbox |
|
| space | toggle checkbox |
|
||||||
| a-x | toggle current element DONE |
|
| a-s | toggle status |
|
||||||
|
| a-x | toggle status DONE |
|
||||||
|
| a-r | toggle status REJECT |
|
||||||
| c-z | normal: undo |
|
| c-z | normal: undo |
|
||||||
| c-s-z | normal: redo |
|
| c-s-z | normal: redo |
|
||||||
| c | normal: crop current node |
|
| c | normal: crop current node |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user