Updated block deletion behavior

This commit is contained in:
Cavallium 2018-10-04 09:52:14 +02:00
parent 658c5669f0
commit a9395277c9
13 changed files with 71 additions and 14 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@ font_gputest4.png
font_gputest4.xcf font_gputest4.xcf
manager2/ manager2/
VBO_Example.java VBO_Example.java
math-rules-cache.zip
/target/ /target/
!/target/*.jar !/target/*.jar

View File

@ -40,7 +40,9 @@ public abstract class Block implements TreeBlock, GraphicalElement {
* Used only to get inner blocks when deleting the parent block. * Used only to get inner blocks when deleting the parent block.
* @return every block of every inner container, or null if empty * @return every block of every inner container, or null if empty
*/ */
public abstract ObjectArrayList<Block> getAllInnerBlocks(); public abstract ObjectArrayList<Block> getInnerBlocks();
public abstract int getInnerContainersCount();
@Override @Override
public abstract void recomputeDimensions(); public abstract void recomputeDimensions();

View File

@ -67,8 +67,13 @@ public class BlockChar extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return null; return null;
} }
@Override
public int getInnerContainersCount() {
return 0;
}
} }

View File

@ -219,9 +219,12 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
final int deltaCaret = caret.getRemaining(); final int deltaCaret = caret.getRemaining();
removed = removed | b.delBlock(caret); removed = removed | b.delBlock(caret);
if (caret.getRemaining() == 0 || removed == false && deltaCaret >= 0 && caret.getRemaining() < 0) { if (caret.getRemaining() == 0 || removed == false && deltaCaret >= 0 && caret.getRemaining() < 0) {
ObjectArrayList<Block> blocks = this.getBlockAt(pos - 1).get().getAllInnerBlocks(); ObjectArrayList<Block> blocks = this.getBlockAt(pos - 1).get().getInnerBlocks();
int innerContainersCount = this.getBlockAt(pos - 1).get().getInnerContainersCount();
if (innerContainersCount > 0) {
innerContainersCount--;
}
removeAt(pos - 1); removeAt(pos - 1);
caret.setPosition(caret.getPosition() - deltaCaret);
if (blocks != null) { if (blocks != null) {
ObjectListIterator<Block> blocksIterator = blocks.iterator(); ObjectListIterator<Block> blocksIterator = blocks.iterator();
int blockNum = 0; int blockNum = 0;
@ -231,6 +234,7 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
blockNum++; blockNum++;
} }
} }
caret.setPosition(caret.getPosition() - innerContainersCount);
removed = true; removed = true;
} }
} }

View File

@ -122,9 +122,14 @@ public class BlockDivision extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
ObjectArrayList<Block> output = containerUp.getContent(); ObjectArrayList<Block> output = containerUp.getContent();
output.addAll(containerDown.getContent()); output.addAll(containerDown.getContent());
return output; return output;
} }
@Override
public int getInnerContainersCount() {
return 2;
}
} }

View File

@ -161,10 +161,15 @@ public class BlockLogarithm extends Block implements IParenthesis {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
ObjectArrayList<Block> output = containerBase.getContent(); ObjectArrayList<Block> output = containerBase.getContent();
output.addAll(containerNumber.getContent()); output.addAll(containerNumber.getContent());
return output; return output;
} }
@Override
public int getInnerContainersCount() {
return 2;
}
} }

View File

@ -21,8 +21,13 @@ public class BlockParenthesis extends BlockParenthesisAbstract {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return getNumberContainer().getContent(); return getNumberContainer().getContent();
} }
@Override
public int getInnerContainersCount() {
return 1;
}
} }

View File

@ -117,8 +117,13 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return containerNumber.getContent(); return containerNumber.getContent();
} }
@Override
public int getInnerContainersCount() {
return 1;
}
} }

View File

@ -83,7 +83,12 @@ public class BlockPower extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return this.containerExponent.getContent(); return this.containerExponent.getContent();
} }
@Override
public int getInnerContainersCount() {
return 1;
}
} }

View File

@ -89,7 +89,12 @@ public class BlockPower2 extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return containerExponent.getContent(); return containerExponent.getContent();
} }
@Override
public int getInnerContainersCount() {
return 1;
}
} }

View File

@ -98,9 +98,14 @@ public class BlockSquareRoot extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
ObjectArrayList<Block> output = containerNumber.getContent(); ObjectArrayList<Block> output = containerNumber.getContent();
// output.addAll(); // output.addAll();
return output; return output;
} }
@Override
public int getInnerContainersCount() {
return 1; //2
}
} }

View File

@ -61,8 +61,13 @@ public class BlockUndefined extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return null; return null;
} }
@Override
public int getInnerContainersCount() {
return 0;
}
} }

View File

@ -258,7 +258,12 @@ public class BlockVariable extends Block {
} }
@Override @Override
public ObjectArrayList<Block> getAllInnerBlocks() { public ObjectArrayList<Block> getInnerBlocks() {
return null; return null;
} }
@Override
public int getInnerContainersCount() {
return 0;
}
} }