added basic selection -- stub

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-09-30 17:27:28 +03:00
parent 66c29d3f21
commit 76f7a94559
3 changed files with 23 additions and 4 deletions

View File

@ -51,6 +51,11 @@
display: none;
}
/* XXX are we selecting subtrees or blocks??? */
.editor [selected] {
background: silver;
}
.editor div:focus {
/*outline: solid 0.2em silver;*/
outline: none;

View File

@ -101,7 +101,7 @@ var Outline = {
: node == 'editable' ?
[...this.dom.querySelectorAll('[tabindex]>textarea')]
: node == 'selected' ?
[...this.dom.querySelectorAll('[tabindex].selected')]
[...this.dom.querySelectorAll('[tabindex][selected]')]
: node == 'top' ?
[...this.dom.children]
.filter(function(elem){
@ -349,6 +349,16 @@ var Outline = {
var next = this.get('next')
this.get()?.remove()
next?.focus() },
// select...
' ': function(evt){
if(this.get('edited') != null){
return }
evt.preventDefault()
var focused = this.get()
focused.getAttribute('selected') != null ?
focused.removeAttribute('selected')
: focused.setAttribute('selected', '') },
},
setup: function(dom){

View File

@ -9,12 +9,13 @@
<script src="editor.js"></script>
<script>
var editor
var setup = function(){
window.editor = {
__proto__: Outline,
}.setup(
document.querySelector('.editor'))
}
document.querySelector('.editor')) }
</script>
</head>
@ -58,7 +59,10 @@ TODO:
- <s>shift subtree up/down</s>
- <s>create node</s>
- <s>edit node</s>
- undo delete node
- undo
- delete node
- indent/deindent
- edit node
- copy/paste nodes/trees
- shifting nodes up/down
- multiple node selection