Skip to content

Delete when in a placeholder should simplify containing expression #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6a3d01a
Implemented for fractions, radicals and superscripts
Happypig375 May 24, 2020
9e8e435
Added tests
Happypig375 May 24, 2020
98aa35d
More tests
Happypig375 May 24, 2020
eccb0a8
Tests for Inner
Happypig375 May 24, 2020
ab4a4a7
Delete trash
Happypig375 May 24, 2020
638bd1e
Tests for delete at beginnning of script when both scripts are present
Happypig375 May 24, 2020
f6db396
Also add power counterpart for this test
Happypig375 May 24, 2020
8e2d2ca
And placeholder counterparts
Happypig375 May 24, 2020
fc58258
Deleting placeholders at the start should not eliminate scripts
Happypig375 May 25, 2020
4ec984c
More range checking
Happypig375 May 27, 2020
5616369
Merge branch 'master' into issue108/DeleteInPlaceholder in order to make
Happypig375 May 27, 2020
f018231
Remove refs on MathListIndex inputs
charlesroddie Jun 17, 2020
85427c6
Move IsBeforeSubList and PreviousOrBeforeWholeList to prevent usage i…
charlesroddie Jun 17, 2020
4858a68
Rename SetTo to ReplaceWith
charlesroddie Jun 17, 2020
624ce67
Accepted simplification recommendations
charlesroddie Jun 25, 2020
bf87ef0
Merge branch 'master' into issue108/DeleteInPlaceholder
Happypig375 Aug 5, 2020
da9c95b
Merge branch 'issue108/DeleteInPlaceholder' of https://github.com/ver…
charlesroddie Aug 10, 2020
4d2b72a
tweak wording
charlesroddie Aug 10, 2020
c8675a1
remove unnecessary null checks
charlesroddie Aug 11, 2020
ac01721
add documentation TODOs
charlesroddie Aug 11, 2020
5b1ad8e
Add TODOs
charlesroddie Aug 11, 2020
9e91a94
failing test is unnecessary
charlesroddie Aug 11, 2020
5a764bb
add TODO
charlesroddie Aug 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions CSharpMath.Editor/Extensions/MathList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,25 @@ public static void InsertAndAdvance(this MathList self, ref MathListIndex index,
throw new SubIndexTypeMismatchException(index);
}
}

public static MathListIndex? PreviousOrBeforeWholeList(MathListIndex index) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an extension method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps. I tried to move it inside the Delete method because the xml comment said "only use from Delete..." but it also needed to be used in DeleteBackwards in MathKeyboard.

return
index.SubIndexType switch
{
MathListSubIndexType.None => index.AtomIndex > -1 ? MathListIndex.Level0Index(index.AtomIndex - 1) : null,
_ =>
(index.SubIndex == null) ? null :
PreviousOrBeforeWholeList(index.SubIndex) is MathListIndex prevSubIndex
? MathListIndex.IndexAtLocation(index.AtomIndex, index.SubIndexType, prevSubIndex) : null,
};
}
public static void RemoveAt(this MathList self, MathListIndex index) {
static bool IsBeforeSubList(MathListIndex index) {
return (index.SubIndex != null && index.SubIndex.AtomIndex == -1) && index.SubIndexType == MathListSubIndexType.None;
}

void RemoveAtInnerList<TAtom>(TAtom atom, int innerListIndex) where TAtom : MathAtom, IMathListContainer {
if (index.SubIndex is null) throw new InvalidCodePathException($"{nameof(index.SubIndex)} should exist");
if (index.IsBeforeSubList) {
if (IsBeforeSubList(index)) {
index.SetTo(
index.LevelDown()
?? throw new InvalidCodePathException($"{nameof(index.SubIndex)} is not null but {nameof(index.LevelDown)} is null"));
Expand All @@ -112,7 +126,7 @@ void RemoveAtInnerList<TAtom>(TAtom atom, int innerListIndex) where TAtom : Math
void RemoveAtInnerScript(ref MathListIndex index, MathAtom atom, bool superscript) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this function

if (index.SubIndex is null) throw new InvalidCodePathException($"{nameof(index.SubIndex)} should exist");
var script = superscript ? atom.Superscript : atom.Subscript;
if (index.IsBeforeSubList) {
if (IsBeforeSubList(index)) {
index.SetTo(
index.LevelDown()
?? throw new InvalidCodePathException($"{nameof(index.SubIndex)} is not null but {nameof(index.LevelDown)} is null"));
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Editor/MathKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void MoveCursorRight() {

void DeleteBackwards() {
// delete the last atom from the list
if (HasText && _insertionIndex.PreviousOrBeforeWholeList is MathListIndex previous) {
if (HasText && (Extensions.PreviousOrBeforeWholeList(_insertionIndex)) is MathListIndex previous) {
_insertionIndex = previous;
MathList.RemoveAt(_insertionIndex);
}
Expand Down
8 changes: 0 additions & 8 deletions CSharpMath.Editor/MathListIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ public MathListIndex LevelUpWithSubIndex(MathListSubIndexType type, MathListInde
MathListSubIndexType.None => AtomIndex > 0 ? Level0Index(AtomIndex - 1) : null,
_ => SubIndex?.Previous is MathListIndex prevSubIndex ? IndexAtLocation(AtomIndex, SubIndexType, prevSubIndex) : null,
};
/// <summary>Should be used inside <see cref="Extensions.RemoveAt(Atom.MathList, ref MathListIndex)"/> only!</summary>
internal bool IsBeforeSubList => SubIndex is { AtomIndex: -1, SubIndexType: MathListSubIndexType.None };
/// <summary>Valid for <see cref="Extensions.RemoveAt(Atom.MathList, ref MathListIndex)"/> only!</summary>
internal MathListIndex? PreviousOrBeforeWholeList => SubIndexType switch
{
MathListSubIndexType.None => AtomIndex > -1 ? Level0Index(AtomIndex - 1) : null,
_ => SubIndex?.PreviousOrBeforeWholeList is MathListIndex prevSubIndex ? IndexAtLocation(AtomIndex, SubIndexType, prevSubIndex) : null,
};

///<summary>Returns the next index.</summary>
public MathListIndex Next => SubIndexType switch
Expand Down