diff --git a/.gitignore b/.gitignore index eb29d91b..8a117c39 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ font_gputest4.png font_gputest4.xcf manager2/ VBO_Example.java +math-rules-cache.zip /target/ !/target/*.jar diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java index 35baae09..a942c7e2 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/Block.java @@ -40,8 +40,10 @@ public abstract class Block implements TreeBlock, GraphicalElement { * Used only to get inner blocks when deleting the parent block. * @return every block of every inner container, or null if empty */ - public abstract ObjectArrayList getAllInnerBlocks(); + public abstract ObjectArrayList getInnerBlocks(); + public abstract int getInnerContainersCount(); + @Override public abstract void recomputeDimensions(); diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java index ca579562..1008e36a 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockChar.java @@ -67,8 +67,13 @@ public class BlockChar extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return null; } + @Override + public int getInnerContainersCount() { + return 0; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java index 8541d545..f2be80c4 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockContainer.java @@ -219,18 +219,22 @@ public class BlockContainer implements TreeContainer, GraphicalElement { final int deltaCaret = caret.getRemaining(); removed = removed | b.delBlock(caret); if (caret.getRemaining() == 0 || removed == false && deltaCaret >= 0 && caret.getRemaining() < 0) { - ObjectArrayList blocks = this.getBlockAt(pos - 1).get().getAllInnerBlocks(); + ObjectArrayList blocks = this.getBlockAt(pos - 1).get().getInnerBlocks(); + int innerContainersCount = this.getBlockAt(pos - 1).get().getInnerContainersCount(); + if (innerContainersCount > 0) { + innerContainersCount--; + } removeAt(pos - 1); - caret.setPosition(caret.getPosition() - deltaCaret); if (blocks != null) { ObjectListIterator blocksIterator = blocks.iterator(); int blockNum = 0; while (blocksIterator.hasNext()) { Block block = blocksIterator.next(); - addBlockUnsafe(pos - 1+blockNum, block); + addBlockUnsafe(pos - 1 + blockNum, block); blockNum++; } } + caret.setPosition(caret.getPosition() - innerContainersCount); removed = true; } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java index ff368273..18e31c59 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockDivision.java @@ -122,9 +122,14 @@ public class BlockDivision extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { ObjectArrayList output = containerUp.getContent(); output.addAll(containerDown.getContent()); return output; } + + @Override + public int getInnerContainersCount() { + return 2; + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java index b234c227..c9cd2c03 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java @@ -161,10 +161,15 @@ public class BlockLogarithm extends Block implements IParenthesis { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { ObjectArrayList output = containerBase.getContent(); output.addAll(containerNumber.getContent()); return output; } + @Override + public int getInnerContainersCount() { + return 2; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java index 6618de2c..01f40696 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesis.java @@ -21,8 +21,13 @@ public class BlockParenthesis extends BlockParenthesisAbstract { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return getNumberContainer().getContent(); } + @Override + public int getInnerContainersCount() { + return 1; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java index 4a64695b..2f28adcd 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockParenthesisAbstract.java @@ -117,8 +117,13 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return containerNumber.getContent(); } + + @Override + public int getInnerContainersCount() { + return 1; + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java index 3632a354..f70121a5 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower.java @@ -83,7 +83,12 @@ public class BlockPower extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return this.containerExponent.getContent(); } + + @Override + public int getInnerContainersCount() { + return 1; + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java index 22ab21cf..3721281d 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockPower2.java @@ -89,7 +89,12 @@ public class BlockPower2 extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return containerExponent.getContent(); } + + @Override + public int getInnerContainersCount() { + return 1; + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java index c87ed2e0..48a23396 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockSquareRoot.java @@ -98,9 +98,14 @@ public class BlockSquareRoot extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { ObjectArrayList output = containerNumber.getContent(); // output.addAll(); return output; } + + @Override + public int getInnerContainersCount() { + return 1; //2 + } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java index 39d529b2..e6cb92de 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockUndefined.java @@ -61,8 +61,13 @@ public class BlockUndefined extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return null; } + @Override + public int getInnerContainersCount() { + return 0; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java index f7c87a3a..4af7a821 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockVariable.java @@ -258,7 +258,12 @@ public class BlockVariable extends Block { } @Override - public ObjectArrayList getAllInnerBlocks() { + public ObjectArrayList getInnerBlocks() { return null; } + + @Override + public int getInnerContainersCount() { + return 0; + } }