From 730cf2aa92093e0b905fb2e8e5d02781405165f3 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Fri, 9 Aug 2019 15:28:08 +0300 Subject: [PATCH 01/12] update --- .../Extensions/DisplayEditingExtensions.Fraction.cs | 4 ++-- .../Extensions/DisplayEditingExtensions.List.cs | 8 ++++++-- .../Extensions/DisplayEditingExtensions.TextLine.cs | 13 +++++++++---- .../Extensions/DisplayEditingExtensions.cs | 4 +++- CSharpMath/Atoms/Range.cs | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index 43b735631..a6f9b2f33 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -19,8 +19,8 @@ public static MathListIndex IndexForPoint(this FractionDisplay(this ListDisplay(this ListDisplay= self.Width + PixelDelta) // All the way to the right - return MathListIndex.Level0Index(self.Range.End); + return self.Range.End < 0 ? null : MathListIndex.Level0Index(self.Range.End); else // It is within the ListDisplay but not within the X bounds of any sublist. Use the closest in that case. displayWithPoint = closest; @@ -57,6 +58,9 @@ public static MathListIndex IndexForPoint(this ListDisplay closestLine) { if (closestLine.LinePosition is Enumerations.LinePosition.Regular) throw Arg($"{nameof(ListDisplay)} {nameof(ListDisplay.LinePosition)} {nameof(Enumerations.LinePosition.Regular)} " + diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs index 1c9eb7ab8..8d2ace149 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs @@ -15,9 +15,11 @@ public partial class DisplayEditingExtensions { float x = 0; var advances = context.GlyphBoundsProvider.GetAdvancesForGlyphs(line.Font, line.Glyphs.AsForEach(), line.Length).Advances; foreach (var (advance, kernAfter) in advances.Zip(line.GlyphInfos.Select(g => g.KernAfterGlyph), ValueTuple.Create)) - if (x <= offset && offset < advance + x) - return i; - else { + if (x <= offset && offset < advance + x) { + if (Math.Abs(offset - x) < Math.Abs(advance + x - offset)) + return i; + return i + 1; + } else { x += advance + kernAfter; i++; if (offset < x) //If the point is in the kern after this, then the index is the one after this @@ -71,10 +73,13 @@ public static MathListIndex IndexForPoint(this TextLineDisplay self.Range.Length) throw new InvalidCodePathException($"Returned index out of range: {index}, range ({self.Range.Location}, {self.Range.Length})"); diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs index 475bce657..2ed5bc852 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs @@ -67,7 +67,9 @@ public static float DistanceFromPointToRect(PointF point, RectangleF rect) { distance += point.Y - rect.YMax(); return distance; } - + public static float DistanceBetweenY(PointF p1, PointF p2) { + return (p1.Y - p2.Y) * (p1.Y - p2.Y); + } /// /// Finds the index in the mathlist before which a new character should be inserted.Returns null if it cannot find the index. /// diff --git a/CSharpMath/Atoms/Range.cs b/CSharpMath/Atoms/Range.cs index 3423bbc50..ff32870f4 100644 --- a/CSharpMath/Atoms/Range.cs +++ b/CSharpMath/Atoms/Range.cs @@ -36,7 +36,7 @@ public Range(int location, int length) { public override bool Equals(object obj) => obj is Range r && this == r; public override int GetHashCode() => unchecked(13 * Length.GetHashCode() + Location.GetHashCode()); public override string ToString() => $@"{{{Location}, {Length}}}"; - public bool Contains(int i) => i >= Location && i <= End; + public bool Contains(int i) => i >= Location && i < Location + End; public Range Slice(int start, int length) => new Range(Location + start, length); public static Range Combine(IEnumerable ranges) { From 44e9dd0bf52a8fa27c456107afa1b7d6f91bdcb0 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Fri, 9 Aug 2019 19:44:17 +0300 Subject: [PATCH 02/12] update --- .../Extensions/DisplayEditingExtensions.Fraction.cs | 2 +- CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index a6f9b2f33..3de497c27 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -31,7 +31,7 @@ public static MathListIndex IndexForPoint(this FractionDisplay(this FractionDisplay self, MathListIndex index, Color color) where TFont : IFont { diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs index 1bf9073c5..44b840fc3 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs @@ -58,9 +58,6 @@ public static MathListIndex IndexForPoint(this ListDisplay closestLine) { if (closestLine.LinePosition is Enumerations.LinePosition.Regular) throw Arg($"{nameof(ListDisplay)} {nameof(ListDisplay.LinePosition)} {nameof(Enumerations.LinePosition.Regular)} " + From 2b1bab37e76496a508fff8f05ac545fa88e9e0dc Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Sat, 10 Aug 2019 19:49:19 +0300 Subject: [PATCH 03/12] clean up --- .../DisplayEditingExtensions.Fraction.cs | 1 - .../DisplayEditingExtensions.TextLine.cs | 14 ++++---------- .../Extensions/DisplayEditingExtensions.cs | 5 ++--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index 3de497c27..ee4421f7e 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -30,7 +30,6 @@ public static MathListIndex IndexForPoint(this FractionDisplay(this FractionDisplay self, TypesettingContext context, MathListIndex index) where TFont : IFont { if (index.SubIndexType != MathListSubIndexType.None) throw Arg("The subindex must be none to get the closest point for it.", nameof(index)); - // draw a caret after the fraction return new PointF(self.DisplayBounds.Left, self.Position.Y); } diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs index 8d2ace149..f0b351edf 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs @@ -69,22 +69,16 @@ public static int MathListIndexToStringIndex(this TextLineDisplay public static MathListIndex IndexForPoint(this TextLineDisplay self, TypesettingContext context, PointF point) where TFont : IFont { // Convert the point to the reference of the CTLine var relativePoint = new PointF(point.X - self.Position.X, point.Y - self.Position.Y); - var indices = self.Runs.Select(run => run.Run.GlyphIndexForXOffset(context, relativePoint.Plus(run.Position).X)).Where(x => x.HasValue); - if (indices.IsEmpty()) + var indices = self.Runs.Select(run => run.Run.GlyphIndexForXOffset(context, relativePoint.Plus(run.Position).X)).Where(x => x.HasValue).ToArray(); + if (indices.Length == 0) return null; var index = indices.Single().GetValueOrDefault(); - var mlIndex = index; - // The index returned is in UTF-16, translate to codepoint index. - // NSUInteger codePointIndex = stringIndexToCodePointIndex(self.attributedString.string, index); - // Convert the code point index to an index into the mathlist - // self.StringIndexToMathListIndex(index); - // index will be between 0 and _range.length inclusive - if (mlIndex < 0 || mlIndex > self.Range.Length) + if (index < 0 || index > self.Range.Length) throw new InvalidCodePathException($"Returned index out of range: {index}, range ({self.Range.Location}, {self.Range.Length})"); // translate to the current index - return MathListIndex.Level0Index(self.Range.Location + mlIndex); + return MathListIndex.Level0Index(self.Range.Location + index); } public static (TextRunDisplay run, int charIndex) GetRunAndCharIndexFromStringIndex(this TextLineDisplay self, int lineCharIndex) where TFont : IFont { diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs index 2ed5bc852..6eb21405d 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.cs @@ -67,9 +67,8 @@ public static float DistanceFromPointToRect(PointF point, RectangleF rect) { distance += point.Y - rect.YMax(); return distance; } - public static float DistanceBetweenY(PointF p1, PointF p2) { - return (p1.Y - p2.Y) * (p1.Y - p2.Y); - } + public static float DistanceBetweenY(PointF p1, PointF p2) => (p1.Y - p2.Y) * (p1.Y - p2.Y); + /// /// Finds the index in the mathlist before which a new character should be inserted.Returns null if it cannot find the index. /// From 9b21411d5cddc26251100a828e8313fd89451a2b Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Mon, 12 Aug 2019 00:27:18 +0300 Subject: [PATCH 04/12] some reverts and fixes --- .../DisplayEditingExtensions.Fraction.cs | 3 +- .../DisplayEditingExtensions.List.cs | 28 ++++++++++++++++--- .../CSharpMath.Forms.Example/EditorPage.xaml | 7 ----- .../EditorPage.xaml.cs | 28 ++++++++++++++++--- CSharpMath.Forms/MathKeyboard.xaml.cs | 4 +++ CSharpMath/Atoms/Range.cs | 2 +- 6 files changed, 55 insertions(+), 17 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index ee4421f7e..a6f9b2f33 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -30,7 +30,8 @@ public static MathListIndex IndexForPoint(this FractionDisplay(this FractionDisplay self, TypesettingContext context, MathListIndex index) where TFont : IFont { if (index.SubIndexType != MathListSubIndexType.None) throw Arg("The subindex must be none to get the closest point for it.", nameof(index)); - return new PointF(self.DisplayBounds.Left, self.Position.Y); + // draw a caret after the fraction + return new PointF(self.DisplayBounds.Right, self.Position.Y); } public static void HighlightCharacterAt(this FractionDisplay self, MathListIndex index, Color color) where TFont : IFont { diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs index 44b840fc3..753e09287 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs @@ -2,7 +2,7 @@ namespace CSharpMath.Editor { using System; using System.Collections.Generic; using System.Drawing; - + using System.Linq; using Display; using Display.Text; using FrontEnd; @@ -34,10 +34,18 @@ public static MathListIndex IndexForPoint(this ListDisplay= self.Width + PixelDelta) + else if (translatedPoint.X >= self.Width + PixelDelta) { + // All the way to the right + var closer = + self.Displays + .OrderBy(d => DistanceFromPointToRect(translatedPoint, new RectangleF(d.Position, d.DisplayBounds.Size))) + .FirstOrDefault(); + if (closer != null) { + return MathListIndex.Level0Index(closer.Range.End); + } // All the way to the right return self.Range.End < 0 ? null : MathListIndex.Level0Index(self.Range.End); - else + } else // It is within the ListDisplay but not within the X bounds of any sublist. Use the closest in that case. displayWithPoint = closest; break; @@ -89,7 +97,19 @@ public static MathListIndex IndexForPoint(this ListDisplay + d is ListDisplay ld && + ld.IndexInParent == index.AtomIndex - 1 + ); + if (scripted != null && mainPosition != null) { + position = new PointF(mainPosition.Value.X + scripted.Width, 0); + } else + position = mainPosition; + } break; default: // Recurse diff --git a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml index 9876e0900..94fee8c2a 100644 --- a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml +++ b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml @@ -3,11 +3,4 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CSharpMath.Forms.Example.EditorPage" Title="Editor"> - - - - \ No newline at end of file diff --git a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs index 4de2426a6..a275e51c3 100644 --- a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs +++ b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs @@ -3,24 +3,44 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - +using CSharpMath.Editor; +using SkiaSharp.Views.Forms; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace CSharpMath.Forms.Example { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class EditorPage : ContentPage { + public EditorPage() { InitializeComponent(); - var view = new global::SkiaSharp.Views.Forms.SKCanvasView { WidthRequest = 320, HeightRequest = 225 }; + this.Content = new EditorView(); + } + + } + + public class EditorView : ContentView { + private MathKeyboard keyboard; + + public EditorView() { + keyboard = new MathKeyboard(); + + var view = new global::SkiaSharp.Views.Forms.SKCanvasView { WidthRequest = 320, HeightRequest = 225, EnableTouchEvents = true }; + view.Touch += + (sender, e) => { + if (e.ActionType == SKTouchAction.Pressed) { + var location = e.Location.ToFormsPoint(); + keyboard.Tap(new System.Drawing.PointF((float)location.X, (float)location.Y)); + } + }; + var painter = new SkiaSharp.MathPainter { TextColor = global::SkiaSharp.SKColors.Black }; - var keyboard = new MathKeyboard(); keyboard.RedrawRequested += (_, __) => view.InvalidateSurface(); view.PaintSurface += (sender, e) => { e.Surface.Canvas.Clear(); SkiaSharp.MathPainter.DrawDisplay(painter, keyboard.Display, e.Surface.Canvas); - keyboard.DrawCaret(e.Surface.Canvas, Rendering.CaretShape.UpArrow); + keyboard.DrawCaret(e.Surface.Canvas, Rendering.CaretShape.IBeam); }; Content = new StackLayout { Children = { view, keyboard } }; } diff --git a/CSharpMath.Forms/MathKeyboard.xaml.cs b/CSharpMath.Forms/MathKeyboard.xaml.cs index a54da817c..e58a67f68 100644 --- a/CSharpMath.Forms/MathKeyboard.xaml.cs +++ b/CSharpMath.Forms/MathKeyboard.xaml.cs @@ -8,6 +8,7 @@ using Xamarin.Forms.Xaml; namespace CSharpMath.Forms { + using CSharpMath.Editor; using Rendering; [XamlCompilation(XamlCompilationOptions.Compile)] public partial class MathKeyboard : ContentView { @@ -15,6 +16,9 @@ public MathKeyboard() { InitializeComponent(); } + + public void Tap(System.Drawing.PointF point) => Keyboard.Tap(point); + public void DrawCaret(global::SkiaSharp.SKCanvas canvas, CaretShape shape = CaretShape.UpArrow) => Keyboard.DrawCaret(new SkiaSharp.SkiaCanvas(canvas, global::SkiaSharp.SKStrokeCap.Butt, false), shape); public event EventHandler RedrawRequested { diff --git a/CSharpMath/Atoms/Range.cs b/CSharpMath/Atoms/Range.cs index ff32870f4..3423bbc50 100644 --- a/CSharpMath/Atoms/Range.cs +++ b/CSharpMath/Atoms/Range.cs @@ -36,7 +36,7 @@ public Range(int location, int length) { public override bool Equals(object obj) => obj is Range r && this == r; public override int GetHashCode() => unchecked(13 * Length.GetHashCode() + Location.GetHashCode()); public override string ToString() => $@"{{{Location}, {Length}}}"; - public bool Contains(int i) => i >= Location && i < Location + End; + public bool Contains(int i) => i >= Location && i <= End; public Range Slice(int start, int length) => new Range(Location + start, length); public static Range Combine(IEnumerable ranges) { From d840553b3a56dd1a4942ec1c3d4c2335d3cacb95 Mon Sep 17 00:00:00 2001 From: Happypig375 Date: Mon, 12 Aug 2019 06:01:44 +0800 Subject: [PATCH 05/12] More cleaning --- .../CSharpMath.Forms.Example/EditorPage.xaml.cs | 5 ++--- CSharpMath.Forms/MathKeyboard.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs index a275e51c3..7ab0c1b74 100644 --- a/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs +++ b/CSharpMath.Forms.Example/CSharpMath.Forms.Example/EditorPage.xaml.cs @@ -25,12 +25,11 @@ public class EditorView : ContentView { public EditorView() { keyboard = new MathKeyboard(); - var view = new global::SkiaSharp.Views.Forms.SKCanvasView { WidthRequest = 320, HeightRequest = 225, EnableTouchEvents = true }; + var view = new SKCanvasView { WidthRequest = 320, HeightRequest = 225, EnableTouchEvents = true }; view.Touch += (sender, e) => { if (e.ActionType == SKTouchAction.Pressed) { - var location = e.Location.ToFormsPoint(); - keyboard.Tap(new System.Drawing.PointF((float)location.X, (float)location.Y)); + keyboard.Tap(new System.Drawing.PointF(e.Location.X, e.Location.Y)); } }; diff --git a/CSharpMath.Forms/MathKeyboard.xaml.cs b/CSharpMath.Forms/MathKeyboard.xaml.cs index e58a67f68..cd6afb574 100644 --- a/CSharpMath.Forms/MathKeyboard.xaml.cs +++ b/CSharpMath.Forms/MathKeyboard.xaml.cs @@ -34,7 +34,7 @@ public event EventHandler DismissPressed { remove => Keyboard.DismissPressed -= value; } - public IDisplay Display => Keyboard.Display; + public IDisplay Display => Keyboard.Display; private void SwitchTab(Grid tab) { tab.IsVisible = true; From e3229f2dbd187d1e547a851eecf68c67848f7632 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Mon, 12 Aug 2019 10:44:56 +0300 Subject: [PATCH 06/12] placeholder case --- .../Extensions/DisplayEditingExtensions.Fraction.cs | 7 +++++-- .../Extensions/DisplayEditingExtensions.TextLine.cs | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index a6f9b2f33..6f253d286 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -30,8 +30,11 @@ public static MathListIndex IndexForPoint(this FractionDisplay(this FractionDisplay self, TypesettingContext context, MathListIndex index) where TFont : IFont { if (index.SubIndexType != MathListSubIndexType.None) throw Arg("The subindex must be none to get the closest point for it.", nameof(index)); - // draw a caret after the fraction - return new PointF(self.DisplayBounds.Right, self.Position.Y); + if (index.AtomIndex == self.Range.End) + // draw a caret after the fraction + return new PointF(self.DisplayBounds.Right, self.Position.Y); + // draw a caret before the fraction + return new PointF(self.DisplayBounds.Left, self.Position.Y); } public static void HighlightCharacterAt(this FractionDisplay self, MathListIndex index, Color color) where TFont : IFont { diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs index f0b351edf..80127d029 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs @@ -10,7 +10,8 @@ namespace CSharpMath.Editor { public partial class DisplayEditingExtensions { public static int? GlyphIndexForXOffset(this AttributedGlyphRun line, TypesettingContext context, float offset) where TFont : IFont { - if (offset < 0) return 0; //Move cursor to index 0 + if (offset < 0) return 0; // Move cursor to index 0 + if (line.Placeholder) return 0; int i = 0; float x = 0; var advances = context.GlyphBoundsProvider.GetAdvancesForGlyphs(line.Font, line.Glyphs.AsForEach(), line.Length).Advances; @@ -22,7 +23,7 @@ public partial class DisplayEditingExtensions { } else { x += advance + kernAfter; i++; - if (offset < x) //If the point is in the kern after this, then the index is the one after this + if (offset < x) // If the point is in the kern after this, then the index is the one after this return i; } return null; From 17c9ffa901e3430667f5c1e784614956591362cb Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Mon, 12 Aug 2019 12:35:42 +0300 Subject: [PATCH 07/12] clean up --- .../Extensions/DisplayEditingExtensions.List.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs index 753e09287..caf33e1e4 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs @@ -36,12 +36,8 @@ public static MathListIndex IndexForPoint(this ListDisplay= self.Width + PixelDelta) { // All the way to the right - var closer = - self.Displays - .OrderBy(d => DistanceFromPointToRect(translatedPoint, new RectangleF(d.Position, d.DisplayBounds.Size))) - .FirstOrDefault(); - if (closer != null) { - return MathListIndex.Level0Index(closer.Range.End); + if (closest != null) { + return MathListIndex.Level0Index(closest.Range.End); } // All the way to the right return self.Range.End < 0 ? null : MathListIndex.Level0Index(self.Range.End); From 2e6788c0a934c21f6ae638d1993a3576b6463614 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Mon, 12 Aug 2019 12:54:32 +0300 Subject: [PATCH 08/12] returns next index rather than null for textLine display --- .../Extensions/DisplayEditingExtensions.TextLine.cs | 2 +- CSharpMath/CSharpMath.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs index 80127d029..0e5bbeeab 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.TextLine.cs @@ -26,7 +26,7 @@ public partial class DisplayEditingExtensions { if (offset < x) // If the point is in the kern after this, then the index is the one after this return i; } - return null; + return i; } public static float XOffsetForGlyphIndex(this AttributedGlyphRun line, TypesettingContext context, int index) where TFont : IFont { diff --git a/CSharpMath/CSharpMath.csproj b/CSharpMath/CSharpMath.csproj index 8c611b67f..67275a3d3 100644 --- a/CSharpMath/CSharpMath.csproj +++ b/CSharpMath/CSharpMath.csproj @@ -1,4 +1,4 @@ - + netstandard1.1 latest @@ -38,7 +38,7 @@ - + \ No newline at end of file From f6e84eaf3eac588af292e8fabd3aafdcefa213a7 Mon Sep 17 00:00:00 2001 From: Happypig375 Date: Tue, 13 Aug 2019 06:53:24 +0800 Subject: [PATCH 09/12] Make CSharpMath.Ios buildable again --- CSharpMath.Apple/Drawing/AppleGraphicsContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharpMath.Apple/Drawing/AppleGraphicsContext.cs b/CSharpMath.Apple/Drawing/AppleGraphicsContext.cs index be541e786..a68076c7f 100644 --- a/CSharpMath.Apple/Drawing/AppleGraphicsContext.cs +++ b/CSharpMath.Apple/Drawing/AppleGraphicsContext.cs @@ -5,7 +5,7 @@ using CoreText; using CSharpMath.Display.Text; using CSharpMath.FrontEnd; -using CSharpMath.Structures; +using Color = CSharpMath.Structures.Color; using UIKit; using TFont = CSharpMath.Apple.AppleMathFont; using TGlyph = System.UInt16; From 8b8b2552519d9d24a456608c0539681531e7a9fd Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Tue, 13 Aug 2019 13:46:27 +0300 Subject: [PATCH 10/12] adjust bounds check --- .../Extensions/DisplayEditingExtensions.List.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs index caf33e1e4..0b93c8e4f 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs @@ -18,10 +18,10 @@ public static MathListIndex IndexForPoint(this ListDisplay(this ListDisplay= self.Width - PixelDelta) //The point is close to the end. Only use the selected X bounds if the Y is within range. - if (translatedPoint.Y <= displayWithPoint.DisplayBounds.YMin() - PixelDelta) + if (translatedPoint.Y <= rect.YMin() - PixelDelta) //The point is less than the Y including the delta. Move the cursor to the end rather than in this atom. return MathListIndex.Level0Index(self.Range.End); break; From 3f56d6214e2632be26a1485f160659fe32f648af Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Tue, 13 Aug 2019 18:51:45 +0300 Subject: [PATCH 11/12] update --- .../Extensions/DisplayEditingExtensions.Fraction.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs index 6f253d286..887eb511d 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.Fraction.cs @@ -18,13 +18,14 @@ public static MathListIndex IndexForPoint(this FractionDisplay self.LinePosition + PixelDelta) return MathListIndex.IndexAtLocation(self.Range.Location, self.Numerator.IndexForPoint(context, point), MathListSubIndexType.Numerator); - else + else if (point.Y < self.LinePosition - PixelDelta) return MathListIndex.IndexAtLocation(self.Range.Location, self.Denominator.IndexForPoint(context, point), MathListSubIndexType.Denominator); + if (point.X > self.Position.X + self.Width / 2) + return MathListIndex.Level0Index(self.Range.End); + + return MathListIndex.Level0Index(self.Range.Location); } public static PointF? PointForIndex(this FractionDisplay self, TypesettingContext context, MathListIndex index) where TFont : IFont { From a73838ac9abf69a9e81fae11c1c4a95b13290905 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Thu, 15 Aug 2019 11:39:54 +0300 Subject: [PATCH 12/12] small fix --- CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs index 0b93c8e4f..385eb6e4d 100644 --- a/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs +++ b/CSharpMath.Editor/Extensions/DisplayEditingExtensions.List.cs @@ -20,7 +20,7 @@ public static MathListIndex IndexForPoint(this ListDisplay