fixed collapsing nodes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-10-04 03:00:57 +03:00
parent 2fd8fbdbeb
commit a7d9d9e40f
2 changed files with 8 additions and 8 deletions

View File

@ -26,7 +26,6 @@ var atLine = function(elem, index){
//---------------------------------------------------------------------
var Node = {
dom: undefined,
document: undefined,
@ -251,14 +250,14 @@ var Outline = {
// .toggleCollapse(<state>)
if(['next', true, false].includes(node)){
state = node
node = null }
node ??= this.get()
node = 'focused' }
node = this.get(node)
if(!node
// only nodes with children can be collapsed...
|| !node.querySelector('[tabindex]')){
return }
state = state == 'next' ?
!node.getAttribute('collapsed')
node.getAttribute('collapsed') != ''
: state
if(state){
node.setAttribute('collapsed', '')
@ -267,13 +266,12 @@ var Outline = {
for(var elem of [...node.querySelectorAll('textarea')]){
elem.updateSize() } }
return node },
remove: function(node='focused', offset){
var elem = this.get(...arguments)
var next
if(elem.classList.contains('focused')){
// XXX need to be able to get the next elem on same level...
this.toggleCollapse(elem)
this.toggleCollapse(elem, true)
next = this.get(elem, 'next') }
elem?.remove()
next?.focus()

View File

@ -49,10 +49,12 @@ var setup = function(){
</div>
</div>
<div class="toolbar">
<!-- XXX these all should focus the node back so as not to hide the keyboard on mobine -->
<button onclick="editor.deindent()">&lt;</button>
<button onclick="editor.indent()">&gt;</button>
<button onclick="editor.Block('before').focus()">O</button>
<button onclick="editor.Block('after').focus()">o</button>
<button onclick="editor.Block('before').focus()" style="text-decoration:underline">+</button>
<button onclick="editor.Block('after').focus()" style="text-decoration:overline">+</button>
<button onclick="editor.toggleCollapse()">+/-</button>
<button onclick="editor.remove()">&times;</button>
</div>
</div>