Skip to content

Commit adf886b

Browse files
FremyCompany_cpFremyCompany_cp
authored andcommitted
The new Selection engine is not working properly. I'll start looking at the work on the unified ChildrenHelper. When done, I'm ready to start mapping more keyboard events to actions.
1 parent 6328c61 commit adf886b

11 files changed

+562
-479
lines changed

FC.MathEditor/WpfMathEditor/Classes/ChildrenHelper.vb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,12 @@
450450

451451
InsertBefore(Wrapper, InitialChild)
452452

453-
Dim Children = New SiblingEnumerator(InitialChild, FinalChild)
453+
Dim ICI = If(InitialChild Is Nothing, 0, InitialChild.ChildIndex)
454+
Dim FCI = If(FinalChild Is Nothing, Me.Count, FinalChild.ChildIndex)
455+
Dim Children = New SiblingEnumerator(New SelectionHelper.SelectionPoint(This, ICI), New SelectionHelper.SelectionPoint(This, FCI))
456+
457+
458+
' TODO: Write test on this matter. SiblingEnumerator implementation changed
454459
Dim CurrentChild As MathElement
455460
While Children.MoveNext()
456461
CurrentChild = Children.Current
@@ -480,7 +485,7 @@
480485
''' Gets the enumerator.
481486
''' </summary>
482487
Public Overridable Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of MathElement) Implements System.Collections.Generic.IEnumerable(Of MathElement).GetEnumerator
483-
Return New SiblingEnumerator(Me.First)
488+
Return New SiblingEnumerator(This, True)
484489
End Function
485490

486491
Private Function GetUntypedEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator

FC.MathEditor/WpfMathEditor/Classes/InputHelper.vb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
Public ReadOnly Property CurrentInput As InputHelper
2323
Get
24-
Return This.Selection.CommonAncestror.Input
24+
Return This.Selection.ParentElement.Input
2525
End Get
2626
End Property
2727

@@ -43,7 +43,7 @@
4343
Public Sub ProcessChar(ByVal InputChar As Integer)
4444

4545
' Can't process char if not currently selected
46-
If This.Selection.CommonAncestror IsNot This Then
46+
If This.Selection.ParentElement IsNot This Then
4747
Throw New InvalidOperationException("Sending text input can be done only to the element who host the selection. Modify your code to change the selection before sending any input.")
4848
End If
4949

@@ -64,13 +64,13 @@
6464
This.Selection.DeleteContents()
6565

6666
' Handle chars by right, by left, or by this input helper
67-
If This.Selection.SelectionStart IsNot Nothing AndAlso This.Selection.SelectionStart.Input.ProcessChar_FromRight(InputChar) Then Exit Sub
68-
If This.Selection.SelectionEnd IsNot Nothing AndAlso This.Selection.SelectionEnd.Input.ProcessChar_FromLeft(InputChar) Then Exit Sub
67+
If This.Selection.PreviousSibling IsNot Nothing AndAlso This.Selection.PreviousSibling.Input.ProcessChar_FromRight(InputChar) Then Exit Sub
68+
If This.Selection.NextSibling IsNot Nothing AndAlso This.Selection.NextSibling.Input.ProcessChar_FromLeft(InputChar) Then Exit Sub
6969
If ProcessChar_Internal(InputChar) Then Exit Sub
7070

7171
' When a char wasn't handled neither by right, by left or by current element:
72-
If This.Selection.SelectionEnd Is Nothing Then
73-
This.Selection.MoveNext() : This.Selection.CommonAncestror.Input.ProcessChar(InputChar)
72+
If This.Selection.NextSibling Is Nothing Then
73+
This.Selection.MoveAfterParent() : This.Selection.ParentElement.Input.ProcessChar(InputChar)
7474
End If
7575

7676
End Sub
@@ -88,7 +88,7 @@
8888
If This.Selection.IsEmpty Then
8989

9090
' If the selection is emtpy, try to give the priority to the left element
91-
Dim RightElement = This.Selection.SelectionEnd
91+
Dim RightElement = This.Selection.NextSibling
9292
If RightElement.Input.ProcessDelete_FromLeft() Then
9393
Exit Sub
9494
End If
@@ -107,9 +107,9 @@
107107
End If
108108

109109
' If this element didn't respond to the keypress, we may forward the event to another one
110-
If This.Selection.SelectionEnd Is Nothing Then
111-
This.Selection.MoveNext()
112-
This.Selection.CommonAncestror.Input.ProcessDelete()
110+
If This.Selection.NextSibling Is Nothing Then
111+
This.Selection.MoveAfterParent()
112+
This.Selection.ParentElement.Input.ProcessDelete()
113113
Exit Sub
114114
End If
115115

@@ -120,7 +120,7 @@
120120
If This.Selection.IsEmpty Then
121121

122122
' If the selection is emtpy, try to give the priority to the left element
123-
Dim LeftElement = This.Selection.SelectionStart
123+
Dim LeftElement = This.Selection.PreviousSibling
124124
If (LeftElement IsNot Nothing) AndAlso (LeftElement.Input.ProcessBackSpace_FromRight()) Then
125125
Exit Sub
126126
End If
@@ -139,9 +139,9 @@
139139
End If
140140

141141
' If this element didn't respond to the keypress, we may forward the event to another one
142-
If This.Selection.SelectionStart Is Nothing Then
143-
This.Selection.MovePrevious()
144-
This.Selection.CommonAncestror.Input.ProcessBackSpace()
142+
If This.Selection.PreviousSibling Is Nothing Then
143+
This.Selection.MoveBeforeParent()
144+
This.Selection.ParentElement.Input.ProcessBackSpace()
145145
Exit Sub
146146
End If
147147

@@ -248,12 +248,14 @@
248248

249249
Public Overridable Function ProcessDelete_Internal() As Boolean
250250

251+
' Retreive the first element before the selection
252+
Dim ElementToDelete = This.Selection.NextSibling
253+
251254
' In case there's no element to delete, forward the call
252-
If This.Selection.SelectionStart Is Nothing Then Return False
255+
If ElementToDelete Is Nothing Then Return False
253256

254257
' If there's one element to delete, delete it
255-
This.Selection.MoveLeft(SelectionHelper.SelectionPointType.StartPoint)
256-
This.Selection.DeleteContents()
258+
ElementToDelete.ParentElement.RemoveChild(ElementToDelete)
257259

258260
' Inform that the delete key was handled
259261
Return True
@@ -262,12 +264,14 @@
262264

263265
Public Overridable Function ProcessBackSpace_Internal() As Boolean
264266

267+
' Retreive the first element before the selection
268+
Dim ElementToDelete = This.Selection.PreviousSibling
269+
265270
' In case there's no element to delete, forward the call
266-
If This.Selection.SelectionEnd Is Nothing Then Return False
271+
If ElementToDelete Is Nothing Then Return False
267272

268273
' If there's one element to delete, delete it
269-
This.Selection.MoveRight(SelectionHelper.SelectionPointType.EndPoint)
270-
This.Selection.DeleteContents()
274+
ElementToDelete.ParentElement.RemoveChild(ElementToDelete)
271275

272276
' Inform that the delete key was handled
273277
Return True

FC.MathEditor/WpfMathEditor/Classes/MathElement.XmlTree.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,6 @@ Partial Public MustInherit Class MathElement
400400
End Sub
401401

402402
Private Sub MathElement_SubTreeModified(ByVal sender As Object, ByVal e As TreeEventArgs) Handles Me.SubTreeModified
403-
Me.ParentElement.RaiseSubTreeModified(e)
403+
If Me.ParentElement IsNot Nothing Then Me.ParentElement.RaiseSubTreeModified(e)
404404
End Sub
405405
End Class
Lines changed: 113 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,114 @@
1-
Partial Public Class SelectionHelper0
2-
3-
Public Enum SelectionPointType
4-
StartPoint
5-
EndPoint
6-
Selection
7-
End Enum
8-
9-
Public ReadOnly Property IsEmpty As Boolean
10-
Get
11-
If SelectionStart Is Nothing Then
12-
If SelectionEnd Is Nothing Then
13-
' TODO: Implement HasChildren.... in ChildrenHelper
14-
Return CommonAncestror.Children.First Is Nothing
15-
Else
16-
Return False
17-
End If
18-
Else
19-
Return SelectionStart.NextSibling Is SelectionEnd
20-
End If
21-
End Get
22-
End Property
23-
24-
Public Sub CollapseToEnd()
25-
Dim NewPoint = New Selection(EndPoint.CommonAncestror, EndPoint.CommonAncestror.Children.Before(EndPoint.SelectionStart), EndPoint.SelectionStart)
26-
SetSelection(NewPoint, PointToChange:=SelectionHelper.SelectionPointType.StartPoint)
27-
End Sub
28-
29-
Public Sub CollapseToStart()
30-
' TODO: Implement CollapseToStart
31-
Throw New NotImplementedException()
32-
End Sub
33-
34-
Public Sub MoveNext(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
35-
Dim Sel As Selection = GetSelection(MovedPoint)
36-
Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
37-
Sel.CommonAncestror = E.ParentElement
38-
Sel.SelectionStart = E
39-
Sel.SelectionEnd = E.NextSibling
40-
SetSelection(Sel, MovedPoint)
41-
End Sub
42-
43-
Public Sub MovePrevious(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
44-
Dim Sel As Selection = GetSelection(MovedPoint)
45-
Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
46-
Sel.CommonAncestror = E.ParentElement
47-
Sel.SelectionStart = E.PreviousSibling
48-
Sel.SelectionEnd = E
49-
SetSelection(Sel, MovedPoint)
50-
End Sub
51-
52-
Public Sub MoveLeft(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
53-
54-
Dim Sel As Selection = GetSelection(MovedPoint)
55-
Dim E = Sel.SelectionStart
56-
57-
If E Is Nothing Then
58-
MovePrevious(MovedPoint)
59-
Else
60-
Sel.CommonAncestror = E.ParentElement
61-
Sel.SelectionStart = E.PreviousSibling
62-
Sel.SelectionEnd = E
63-
SetSelection(Sel, MovedPoint)
64-
End If
65-
66-
End Sub
67-
68-
Public Sub MoveRight(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
69-
70-
Dim Sel As Selection = GetSelection(MovedPoint)
71-
Dim E = Sel.SelectionEnd
72-
73-
If E Is Nothing Then
74-
MoveNext(MovedPoint)
75-
Else
76-
Sel.CommonAncestror = E.ParentElement
77-
Sel.SelectionStart = E
78-
Sel.SelectionEnd = E.NextSibling
79-
SetSelection(Sel, MovedPoint)
80-
End If
81-
82-
End Sub
83-
84-
Public Sub MoveStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
85-
86-
Dim Sel As Selection = GetSelection(MovedPoint)
87-
Sel.SelectionStart = Nothing
88-
Sel.SelectionEnd = Sel.CommonAncestror.FirstChild
89-
SetSelection(Sel, MovedPoint)
90-
91-
End Sub
92-
93-
Public Sub MoveEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
94-
95-
Dim Sel As Selection = GetSelection(MovedPoint)
96-
Sel.SelectionEnd = Nothing
97-
Sel.SelectionStart = Sel.CommonAncestror.LastChild
98-
SetSelection(Sel, MovedPoint)
99-
100-
End Sub
101-
102-
Public Sub MoveDocumentStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
103-
104-
SetSelection(New Selection(CommonAncestror.Root, Nothing, CommonAncestror.Root.FirstChild), MovedPoint)
105-
106-
End Sub
107-
108-
Public Sub MoveDocumentEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
109-
110-
SetSelection(New Selection(CommonAncestror.Root, CommonAncestror.Root.LastChild, Nothing), MovedPoint)
111-
112-
End Sub
1+
'Partial Public Class SelectionHelper0
2+
3+
' Public Enum SelectionPointType
4+
' StartPoint
5+
' EndPoint
6+
' Selection
7+
' End Enum
8+
9+
' Public ReadOnly Property IsEmpty As Boolean
10+
' Get
11+
' If SelectionStart Is Nothing Then
12+
' If SelectionEnd Is Nothing Then
13+
' ' TODO: Implement HasChildren.... in ChildrenHelper
14+
' Return CommonAncestror.Children.First Is Nothing
15+
' Else
16+
' Return False
17+
' End If
18+
' Else
19+
' Return SelectionStart.NextSibling Is SelectionEnd
20+
' End If
21+
' End Get
22+
' End Property
23+
24+
' Public Sub CollapseToEnd()
25+
' Dim NewPoint = New Selection(EndPoint.CommonAncestror, EndPoint.CommonAncestror.Children.Before(EndPoint.SelectionStart), EndPoint.SelectionStart)
26+
' SetSelection(NewPoint, PointToChange:=SelectionHelper.SelectionPointType.StartPoint)
27+
' End Sub
28+
29+
' Public Sub CollapseToStart()
30+
' ' TODO: Implement CollapseToStart
31+
' Throw New NotImplementedException()
32+
' End Sub
33+
34+
' Public Sub MoveNext(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
35+
' Dim Sel As Selection = GetSelection(MovedPoint)
36+
' Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
37+
' Sel.CommonAncestror = E.ParentElement
38+
' Sel.SelectionStart = E
39+
' Sel.SelectionEnd = E.NextSibling
40+
' SetSelection(Sel, MovedPoint)
41+
' End Sub
42+
43+
' Public Sub MovePrevious(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
44+
' Dim Sel As Selection = GetSelection(MovedPoint)
45+
' Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
46+
' Sel.CommonAncestror = E.ParentElement
47+
' Sel.SelectionStart = E.PreviousSibling
48+
' Sel.SelectionEnd = E
49+
' SetSelection(Sel, MovedPoint)
50+
' End Sub
51+
52+
' Public Sub MoveLeft(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
53+
54+
' Dim Sel As Selection = GetSelection(MovedPoint)
55+
' Dim E = Sel.SelectionStart
56+
57+
' If E Is Nothing Then
58+
' MovePrevious(MovedPoint)
59+
' Else
60+
' Sel.CommonAncestror = E.ParentElement
61+
' Sel.SelectionStart = E.PreviousSibling
62+
' Sel.SelectionEnd = E
63+
' SetSelection(Sel, MovedPoint)
64+
' End If
65+
66+
' End Sub
67+
68+
' Public Sub MoveRight(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
69+
70+
' Dim Sel As Selection = GetSelection(MovedPoint)
71+
' Dim E = Sel.SelectionEnd
72+
73+
' If E Is Nothing Then
74+
' MoveNext(MovedPoint)
75+
' Else
76+
' Sel.CommonAncestror = E.ParentElement
77+
' Sel.SelectionStart = E
78+
' Sel.SelectionEnd = E.NextSibling
79+
' SetSelection(Sel, MovedPoint)
80+
' End If
81+
82+
' End Sub
83+
84+
' Public Sub MoveStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
85+
86+
' Dim Sel As Selection = GetSelection(MovedPoint)
87+
' Sel.SelectionStart = Nothing
88+
' Sel.SelectionEnd = Sel.CommonAncestror.FirstChild
89+
' SetSelection(Sel, MovedPoint)
90+
91+
' End Sub
92+
93+
' Public Sub MoveEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
94+
95+
' Dim Sel As Selection = GetSelection(MovedPoint)
96+
' Sel.SelectionEnd = Nothing
97+
' Sel.SelectionStart = Sel.CommonAncestror.LastChild
98+
' SetSelection(Sel, MovedPoint)
99+
100+
' End Sub
101+
102+
' Public Sub MoveDocumentStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
103+
104+
' SetSelection(New Selection(CommonAncestror.Root, Nothing, CommonAncestror.Root.FirstChild), MovedPoint)
105+
106+
' End Sub
107+
108+
' Public Sub MoveDocumentEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
109+
110+
' SetSelection(New Selection(CommonAncestror.Root, CommonAncestror.Root.LastChild, Nothing), MovedPoint)
111+
112+
' End Sub
113113

114-
End Class
114+
'End Class

0 commit comments

Comments
 (0)