Skip to content

Commit

Permalink
The new Selection engine is not working properly. I'll start looking …
Browse files Browse the repository at this point in the history
…at the work on the unified ChildrenHelper. When done, I'm ready to start mapping more keyboard events to actions.
  • Loading branch information
FremyCompany_cp authored and FremyCompany_cp committed Jun 22, 2011
1 parent 6328c61 commit adf886b
Show file tree
Hide file tree
Showing 11 changed files with 562 additions and 479 deletions.
9 changes: 7 additions & 2 deletions FC.MathEditor/WpfMathEditor/Classes/ChildrenHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@

InsertBefore(Wrapper, InitialChild)

Dim Children = New SiblingEnumerator(InitialChild, FinalChild)
Dim ICI = If(InitialChild Is Nothing, 0, InitialChild.ChildIndex)
Dim FCI = If(FinalChild Is Nothing, Me.Count, FinalChild.ChildIndex)
Dim Children = New SiblingEnumerator(New SelectionHelper.SelectionPoint(This, ICI), New SelectionHelper.SelectionPoint(This, FCI))


' TODO: Write test on this matter. SiblingEnumerator implementation changed
Dim CurrentChild As MathElement
While Children.MoveNext()
CurrentChild = Children.Current
Expand Down Expand Up @@ -480,7 +485,7 @@
''' Gets the enumerator.
''' </summary>
Public Overridable Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of MathElement) Implements System.Collections.Generic.IEnumerable(Of MathElement).GetEnumerator
Return New SiblingEnumerator(Me.First)
Return New SiblingEnumerator(This, True)
End Function

Private Function GetUntypedEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Expand Down
44 changes: 24 additions & 20 deletions FC.MathEditor/WpfMathEditor/Classes/InputHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Public ReadOnly Property CurrentInput As InputHelper
Get
Return This.Selection.CommonAncestror.Input
Return This.Selection.ParentElement.Input
End Get
End Property

Expand All @@ -43,7 +43,7 @@
Public Sub ProcessChar(ByVal InputChar As Integer)

' Can't process char if not currently selected
If This.Selection.CommonAncestror IsNot This Then
If This.Selection.ParentElement IsNot This Then
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.")
End If

Expand All @@ -64,13 +64,13 @@
This.Selection.DeleteContents()

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

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

End Sub
Expand All @@ -88,7 +88,7 @@
If This.Selection.IsEmpty Then

' If the selection is emtpy, try to give the priority to the left element
Dim RightElement = This.Selection.SelectionEnd
Dim RightElement = This.Selection.NextSibling
If RightElement.Input.ProcessDelete_FromLeft() Then
Exit Sub
End If
Expand All @@ -107,9 +107,9 @@
End If

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

Expand All @@ -120,7 +120,7 @@
If This.Selection.IsEmpty Then

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

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

Expand Down Expand Up @@ -248,12 +248,14 @@

Public Overridable Function ProcessDelete_Internal() As Boolean

' Retreive the first element before the selection
Dim ElementToDelete = This.Selection.NextSibling

' In case there's no element to delete, forward the call
If This.Selection.SelectionStart Is Nothing Then Return False
If ElementToDelete Is Nothing Then Return False

' If there's one element to delete, delete it
This.Selection.MoveLeft(SelectionHelper.SelectionPointType.StartPoint)
This.Selection.DeleteContents()
ElementToDelete.ParentElement.RemoveChild(ElementToDelete)

' Inform that the delete key was handled
Return True
Expand All @@ -262,12 +264,14 @@

Public Overridable Function ProcessBackSpace_Internal() As Boolean

' Retreive the first element before the selection
Dim ElementToDelete = This.Selection.PreviousSibling

' In case there's no element to delete, forward the call
If This.Selection.SelectionEnd Is Nothing Then Return False
If ElementToDelete Is Nothing Then Return False

' If there's one element to delete, delete it
This.Selection.MoveRight(SelectionHelper.SelectionPointType.EndPoint)
This.Selection.DeleteContents()
ElementToDelete.ParentElement.RemoveChild(ElementToDelete)

' Inform that the delete key was handled
Return True
Expand Down
2 changes: 1 addition & 1 deletion FC.MathEditor/WpfMathEditor/Classes/MathElement.XmlTree.vb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,6 @@ Partial Public MustInherit Class MathElement
End Sub

Private Sub MathElement_SubTreeModified(ByVal sender As Object, ByVal e As TreeEventArgs) Handles Me.SubTreeModified
Me.ParentElement.RaiseSubTreeModified(e)
If Me.ParentElement IsNot Nothing Then Me.ParentElement.RaiseSubTreeModified(e)
End Sub
End Class
226 changes: 113 additions & 113 deletions FC.MathEditor/WpfMathEditor/Classes/SelectionHelper.Actions.vb
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
Partial Public Class SelectionHelper0

Public Enum SelectionPointType
StartPoint
EndPoint
Selection
End Enum

Public ReadOnly Property IsEmpty As Boolean
Get
If SelectionStart Is Nothing Then
If SelectionEnd Is Nothing Then
' TODO: Implement HasChildren.... in ChildrenHelper
Return CommonAncestror.Children.First Is Nothing
Else
Return False
End If
Else
Return SelectionStart.NextSibling Is SelectionEnd
End If
End Get
End Property

Public Sub CollapseToEnd()
Dim NewPoint = New Selection(EndPoint.CommonAncestror, EndPoint.CommonAncestror.Children.Before(EndPoint.SelectionStart), EndPoint.SelectionStart)
SetSelection(NewPoint, PointToChange:=SelectionHelper.SelectionPointType.StartPoint)
End Sub

Public Sub CollapseToStart()
' TODO: Implement CollapseToStart
Throw New NotImplementedException()
End Sub

Public Sub MoveNext(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
Dim Sel As Selection = GetSelection(MovedPoint)
Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
Sel.CommonAncestror = E.ParentElement
Sel.SelectionStart = E
Sel.SelectionEnd = E.NextSibling
SetSelection(Sel, MovedPoint)
End Sub

Public Sub MovePrevious(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
Dim Sel As Selection = GetSelection(MovedPoint)
Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
Sel.CommonAncestror = E.ParentElement
Sel.SelectionStart = E.PreviousSibling
Sel.SelectionEnd = E
SetSelection(Sel, MovedPoint)
End Sub

Public Sub MoveLeft(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

Dim Sel As Selection = GetSelection(MovedPoint)
Dim E = Sel.SelectionStart

If E Is Nothing Then
MovePrevious(MovedPoint)
Else
Sel.CommonAncestror = E.ParentElement
Sel.SelectionStart = E.PreviousSibling
Sel.SelectionEnd = E
SetSelection(Sel, MovedPoint)
End If

End Sub

Public Sub MoveRight(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

Dim Sel As Selection = GetSelection(MovedPoint)
Dim E = Sel.SelectionEnd

If E Is Nothing Then
MoveNext(MovedPoint)
Else
Sel.CommonAncestror = E.ParentElement
Sel.SelectionStart = E
Sel.SelectionEnd = E.NextSibling
SetSelection(Sel, MovedPoint)
End If

End Sub

Public Sub MoveStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

Dim Sel As Selection = GetSelection(MovedPoint)
Sel.SelectionStart = Nothing
Sel.SelectionEnd = Sel.CommonAncestror.FirstChild
SetSelection(Sel, MovedPoint)

End Sub

Public Sub MoveEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

Dim Sel As Selection = GetSelection(MovedPoint)
Sel.SelectionEnd = Nothing
Sel.SelectionStart = Sel.CommonAncestror.LastChild
SetSelection(Sel, MovedPoint)

End Sub

Public Sub MoveDocumentStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

SetSelection(New Selection(CommonAncestror.Root, Nothing, CommonAncestror.Root.FirstChild), MovedPoint)

End Sub

Public Sub MoveDocumentEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

SetSelection(New Selection(CommonAncestror.Root, CommonAncestror.Root.LastChild, Nothing), MovedPoint)

End Sub
'Partial Public Class SelectionHelper0

' Public Enum SelectionPointType
' StartPoint
' EndPoint
' Selection
' End Enum

' Public ReadOnly Property IsEmpty As Boolean
' Get
' If SelectionStart Is Nothing Then
' If SelectionEnd Is Nothing Then
' ' TODO: Implement HasChildren.... in ChildrenHelper
' Return CommonAncestror.Children.First Is Nothing
' Else
' Return False
' End If
' Else
' Return SelectionStart.NextSibling Is SelectionEnd
' End If
' End Get
' End Property

' Public Sub CollapseToEnd()
' Dim NewPoint = New Selection(EndPoint.CommonAncestror, EndPoint.CommonAncestror.Children.Before(EndPoint.SelectionStart), EndPoint.SelectionStart)
' SetSelection(NewPoint, PointToChange:=SelectionHelper.SelectionPointType.StartPoint)
' End Sub

' Public Sub CollapseToStart()
' ' TODO: Implement CollapseToStart
' Throw New NotImplementedException()
' End Sub

' Public Sub MoveNext(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
' Dim Sel As Selection = GetSelection(MovedPoint)
' Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
' Sel.CommonAncestror = E.ParentElement
' Sel.SelectionStart = E
' Sel.SelectionEnd = E.NextSibling
' SetSelection(Sel, MovedPoint)
' End Sub

' Public Sub MovePrevious(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)
' Dim Sel As Selection = GetSelection(MovedPoint)
' Dim E = Sel.CommonAncestror.ParentLayoutEngineChild
' Sel.CommonAncestror = E.ParentElement
' Sel.SelectionStart = E.PreviousSibling
' Sel.SelectionEnd = E
' SetSelection(Sel, MovedPoint)
' End Sub

' Public Sub MoveLeft(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' Dim Sel As Selection = GetSelection(MovedPoint)
' Dim E = Sel.SelectionStart

' If E Is Nothing Then
' MovePrevious(MovedPoint)
' Else
' Sel.CommonAncestror = E.ParentElement
' Sel.SelectionStart = E.PreviousSibling
' Sel.SelectionEnd = E
' SetSelection(Sel, MovedPoint)
' End If

' End Sub

' Public Sub MoveRight(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' Dim Sel As Selection = GetSelection(MovedPoint)
' Dim E = Sel.SelectionEnd

' If E Is Nothing Then
' MoveNext(MovedPoint)
' Else
' Sel.CommonAncestror = E.ParentElement
' Sel.SelectionStart = E
' Sel.SelectionEnd = E.NextSibling
' SetSelection(Sel, MovedPoint)
' End If

' End Sub

' Public Sub MoveStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' Dim Sel As Selection = GetSelection(MovedPoint)
' Sel.SelectionStart = Nothing
' Sel.SelectionEnd = Sel.CommonAncestror.FirstChild
' SetSelection(Sel, MovedPoint)

' End Sub

' Public Sub MoveEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' Dim Sel As Selection = GetSelection(MovedPoint)
' Sel.SelectionEnd = Nothing
' Sel.SelectionStart = Sel.CommonAncestror.LastChild
' SetSelection(Sel, MovedPoint)

' End Sub

' Public Sub MoveDocumentStart(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' SetSelection(New Selection(CommonAncestror.Root, Nothing, CommonAncestror.Root.FirstChild), MovedPoint)

' End Sub

' Public Sub MoveDocumentEnd(Optional ByVal MovedPoint As SelectionPointType = SelectionPointType.Selection)

' SetSelection(New Selection(CommonAncestror.Root, CommonAncestror.Root.LastChild, Nothing), MovedPoint)

' End Sub

End Class
'End Class
Loading

0 comments on commit adf886b

Please sign in to comment.