From aa9ce640c9bf454e58d5b4a7c723c95c96c083d3 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 22 Nov 2020 16:19:55 +0100 Subject: [PATCH] First mildly working WebTextBox... no syntax coloring yet --- .../Controls/WebBrowser/WebBrowserEditBox.cs | 26 +++++++++++++++---- .../WebBrowser/WebBrowserEditBox.html | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ui/Controls/WebBrowser/WebBrowserEditBox.cs b/src/ui/Controls/WebBrowser/WebBrowserEditBox.cs index 407b05018..d0bb11a47 100644 --- a/src/ui/Controls/WebBrowser/WebBrowserEditBox.cs +++ b/src/ui/Controls/WebBrowser/WebBrowserEditBox.cs @@ -81,11 +81,10 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser var ch = text[i]; if (ch == '\r') { - //continue + //continue } else if (ch == '\n') { - i++; if (!isNewLine) { sb.Append(Environment.NewLine); @@ -205,7 +204,15 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser } } - public int SelectionLength { get; set; } + public int SelectionLength + { + get => SelectedText.Length; + set + { + //TODO: fix + } + } + public bool HideSelection { get; set; } public void SelectAll() @@ -299,13 +306,15 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser public void ClientClick() { - MouseClick?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1)); + var mp = PointToClient(MousePosition); + MouseClick?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, mp.X, mp.Y, 1)); TextChanged?.Invoke(this, new KeyEventArgs(0)); } public void ClientMouseMove() { - MouseMove?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1)); + var mp = PointToClient(MousePosition); + MouseMove?.Invoke(this, new MouseEventArgs(MouseButtons.None, 0, mp.X, mp.Y, 0)); } internal int GetCharIndexFromPosition(Point pt) @@ -315,10 +324,17 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser public void Clear() { + Text = string.Empty; } public void Undo() { + if (Document == null) + { + return; + } + + Document.ExecCommand("undo", false, null); } public void ClearUndo() diff --git a/src/ui/Controls/WebBrowser/WebBrowserEditBox.html b/src/ui/Controls/WebBrowser/WebBrowserEditBox.html index a68e72771..9fb205cb6 100644 --- a/src/ui/Controls/WebBrowser/WebBrowserEditBox.html +++ b/src/ui/Controls/WebBrowser/WebBrowserEditBox.html @@ -109,7 +109,7 @@ if (node.parentNode.parentNode.id === "myContent" && !node.parentNode.previousSibling) { // skip first P } else { - extraChar = 1; + extraChar = 2; } } @@ -130,6 +130,7 @@ if (node.nodeName === "P" && node.previousSibling) { idx++; + idx++; } var res = getPreviousOrParentLastChild(node);