-
Notifications
You must be signed in to change notification settings - Fork 65
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
Delete when in a placeholder should simplify containing expression #117
base: master
Are you sure you want to change the base?
Conversation
Great. Will review on Mon. |
Functionality seems good from my testing. |
@@ -81,12 +83,66 @@ partial class Extensions { | |||
} | |||
|
|||
public static void RemoveAt(this MathList self, ref MathListIndex index) { | |||
index ??= MathListIndex.Level0Index(0); | |||
void RemoveAtInnerList<TAtom>(ref MathListIndex index, TAtom atom, int innerListIndex) where TAtom : MathAtom, IMathListContainer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document this a bit? It's not clear from the name of the function and inputs:
- Is
atom
an Atom that resides atindex
? - Is
atom
the thing to be removed, or is instead a subatom ofatom
residing atinnerListIndex
withinatom
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atom
is a MathAtom
directly contained in self
that contains(index.SubIndex.AtomIndex > -1
)/is(index.SubIndex.AtomIndex = -1
) the atom to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK that takes us closer. What would be the right type for AtomIndex to have? Nullable<int>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An AtomIndex of -1
indicates deletion at the beginning of line (not pointing to any atom). It is not a valid value for other methods accepting MathListIndex
, which is why PreviousOrBeforeWholeList
is internal
.
if(atom.Subscript.Count > 0) self[tempIndex.AtomIndex - 1].Subscript.Append(atom.Subscript); | ||
} else atom.InnerLists.ElementAt(innerListIndex).RemoveAt(ref index.SubIndex); | ||
} | ||
void RemoveAtInnerScript(ref MathListIndex index, MathAtom atom, bool superscript) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this function
@charlesroddie What is the status of this? |
Main issue is the -1s. I've started doing a bit of cleaning to try to understand this. Removed some refs which allow removing a duplicate "index" input. (Before there were two indexes which were supposed to be the same.) Also moved IsBeforeSubList and PreviousOrBeforeWholeList to prevent usage in the wrong places. It will take more thinking and cleaning to be sure what to do about the -1s. Options: 1. keep the current hack, 2. adjust the docs on MathListIndex to allow it to be either the current "points to a particular character in the MathList" or "a sublist in a MathList", 3. avoid using MathListIndex for deletes. I haven't understood the code well enough to decide on this. |
Does it make sense for a data structure to have a |
@@ -81,11 +81,25 @@ partial class Extensions { | |||
throw new SubIndexTypeMismatchException(index); | |||
} | |||
} | |||
|
|||
public static MathListIndex? PreviousOrBeforeWholeList(MathListIndex index) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
The items are settable anyway so the Replace method isn't doing anything that can't be done without it. I think it's better for clarity than having the ref inputs. Although immutable will be better still :). |
With |
@charlesroddie What now? |
Currently MathListIndex is well documented. We can't disobey its definition. The code in MathList.cs I haven't been able to understand from the names and type signatures. So I wouldn't be able to make a start documenting it. To get this mergeable we'll need to document the functions in MathList.cs and make the usage of MathListIndex compatible with its definition. I'm not sure which of these two is the best place is to begin. I'm happy to take a call on Sat UK morning to look at this code. Do you think we should change MathListIndex to point to any atom in a MathList, rather than just a character at a leaf of the MathList? Or does another type need to be created for this purpose? |
Let's separate the behaviour from the data structures a little. Also this is a bit of a tangent. Personally I prefer treating "sin" as one thing, so you cannot navigate inside it. That's the behavior of LyX for example. Word is illogical about this so we can ignore that. An atom is a basic unit (regardless of whether the smallest atom is "s" or "sin" in "sin"). So a MathListIndex can index into an atom and we can replace "character" with "atom". But that's not the tricky change here. |
What behaviour can be done depends on the data structure. If the structure disallows certain states, then behaviour relying on those states cannot exist. The resolution on
Then again, LyX does not have #83, as
Then again, we can potentially enable dividing MathAtoms into characters just like how we can divide atoms into subatomic particles.
The original documentation from iosMath does seem to use "character" and "atom" interchangeably, so this is also a solution. |
I'm juggling a few things but will have another look at this tomorrow. Can you explain what "deletion at the beginning of line (not pointing to any atom)" means? Perhaps an example? |
I see thanks. And do we need to do anything in that case? Do you have a strong preference about the right behavior when you press delete there? |
I prefer the behaviour as done in this PR before your commits. |
MathQuill deletes the "sin" and moves the 789 down and so does LyX. Word selects the entire "sin^789" expression. What did this branch do? I don't remember committing any behavioural changes in this branch. |
I followed MathQuill.
Yes. See all the failed tests. |
This is a draft until tests pass. |
What's the status of this PR? |
Sorry for delay. I'll look at this today |
…ybadcat/CSharpMath into issue108/DeleteInPlaceholder
What is a "finalized list"? (Wording used in many places and connected with a finalize:bool.) |
I've left TODOs for what would be needed to merge this. The major functions are still unclear to me and I would have to piece them together from their implementations which would take a long time. My guesses about the implementation: the cursor is at a certain position (also described by a MathListIndex I presume?), and there may be a MathListIndex describing something to be deleted to the left of it (your diagram of let rec delete(atom, cursorPosition:MathListIndex) =
match cursorPosition.SubIndex with
| None -> // (this case is not reached recursively)
if cursorPosition.AtomIndex = 0 then atom // do nothing
else remove(atom, getMathIndexBefore cursorPosition)
| Some subIndex ->
if subIndex.Subindex = None && subIndex.AtomIndex = 0 then // on left of SubIndex
match SubIndexType with
| Superscript -> atom.Superscript // replace the atom with the superscript part as in the comments on your diagram
| Subscript -> atom.Subscript
...
else
atom with the subindexed part `inner` replaced with delete(inner,cursorPosition.SubIndex) Doesn't have to be done exactly like this but note the non-use of invalid MathListIndexes. |
I believe a We should bring this constraint into the type structure: remove
I've started this but not ready to commit. |
|
Regarding invalid indexes: Now we use MathListIndex to indicate both spaces between atoms (remove) and atom slots (insert)? |
I think you meant remove and insert the other way around? The interpretation for Atoms is now clear (at least pending resolution of BetweenBaseAndScripts). Representing cursor positions is something I'm trying to understand in order to document. Best to work on this in the other PR (cleaning up MathListIndex). Help appreciated with documentation of the existing structure and code and implementation of BetweenBaseAndScripts there. That will clear a significant piece of technical debt and allow looking at this PR again. |
Implements #108