fix 复制字符后只能在 editor 粘贴
Browse files- src/WpfEditor/TextEditorControl.cs +183 -177
- src/WpfEditor/TreeMenuPage.xaml +2 -2
src/WpfEditor/TextEditorControl.cs
CHANGED
|
@@ -56,7 +56,7 @@ namespace WpfEditor
|
|
| 56 |
}
|
| 57 |
|
| 58 |
public void ShowDraggableImageControl(Mat image, Mat image_orig)
|
| 59 |
-
{
|
| 60 |
var mainWindow = Window.GetWindow(this) as MainWindow;
|
| 61 |
|
| 62 |
// 将Mat转换为BitmapSource
|
|
@@ -176,9 +176,9 @@ namespace WpfEditor
|
|
| 176 |
border.ContextMenu = contextMenu;
|
| 177 |
|
| 178 |
// 显示窗口
|
| 179 |
-
_imageWindow.Show(); // 单行文本图
|
| 180 |
-
|
| 181 |
-
// 根据图片大小调整窗口尺寸
|
| 182 |
AdjustWindowSizeBasedOnImage(_imageWindow, bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
| 183 |
|
| 184 |
// 设置初始位置(居中显示)
|
|
@@ -187,16 +187,16 @@ namespace WpfEditor
|
|
| 187 |
_imageWindow.Left = 0; // mainWindow.Left + (mainWindow.Width - _imageWindow.ActualWidth) / 2;
|
| 188 |
_imageWindow.Top = mainWindow.Top + (mainWindow.Height - _imageWindow.ActualHeight) / 2;
|
| 189 |
}
|
| 190 |
-
|
| 191 |
-
if (mainWindow != null)
|
| 192 |
-
{
|
| 193 |
-
if (true || mainWindow.ImageViewer.Source == null)
|
| 194 |
-
{
|
| 195 |
-
mainWindow.ShowImageInPanel(bitmapSource2); // 全图
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
|
| 200 |
}
|
| 201 |
|
| 202 |
// 根据图片大小调整窗口尺寸的辅助方法
|
|
@@ -482,18 +482,18 @@ namespace WpfEditor
|
|
| 482 |
if (!IsReadOnly)
|
| 483 |
{
|
| 484 |
//InsertText(e.Text);
|
| 485 |
-
InsertTextCharacters(e.Text);
|
| 486 |
-
|
| 487 |
-
// 标记文本已更改
|
| 488 |
-
_textChanged = true;
|
| 489 |
-
|
| 490 |
-
// 触发文本改变事件
|
| 491 |
-
OnTextChanged();
|
| 492 |
-
|
| 493 |
-
// 触发光标位置改变事件
|
| 494 |
-
OnCursorPositionChanged(_cursorLine, _cursorColumn);
|
| 495 |
-
|
| 496 |
-
// 重绘编辑器
|
| 497 |
InvalidateVisual();
|
| 498 |
|
| 499 |
e.Handled = true;
|
|
@@ -618,9 +618,9 @@ namespace WpfEditor
|
|
| 618 |
// InvalidateVisual();
|
| 619 |
//}
|
| 620 |
|
| 621 |
-
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
| 622 |
-
{
|
| 623 |
-
base.OnMouseLeftButtonDown(e);
|
| 624 |
Focus();
|
| 625 |
Point position = e.GetPosition(this);
|
| 626 |
SetCursorPositionFromPoint(position);
|
|
@@ -631,19 +631,19 @@ namespace WpfEditor
|
|
| 631 |
else
|
| 632 |
{
|
| 633 |
UpdateSelection();
|
| 634 |
-
}
|
| 635 |
-
|
| 636 |
-
// 图片中框选光标后面的第一个字符
|
| 637 |
if (e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)
|
| 638 |
{
|
| 639 |
showCurrChar();
|
| 640 |
-
}
|
| 641 |
-
|
| 642 |
e.Handled = true;
|
| 643 |
-
InvalidateVisual();
|
| 644 |
}
|
| 645 |
-
|
| 646 |
-
// 重写右键按下事件
|
| 647 |
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
|
| 648 |
{
|
| 649 |
base.OnMouseRightButtonDown(e);
|
|
@@ -688,31 +688,30 @@ namespace WpfEditor
|
|
| 688 |
if (HasSelection())
|
| 689 |
{
|
| 690 |
_isCut = false;
|
| 691 |
-
// 保存文本内容到剪贴板(兼容性考虑)
|
| 692 |
-
Clipboard.SetText(GetSelectedText());
|
| 693 |
|
| 694 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
try
|
| 696 |
{
|
| 697 |
var characters = GetSelectedTextCharacters();
|
| 698 |
if (characters.Count > 0)
|
| 699 |
{
|
| 700 |
-
// using (MemoryStream ms = new MemoryStream())
|
| 701 |
-
// {
|
| 702 |
-
// System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
|
| 703 |
-
// new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
| 704 |
-
// formatter.Serialize(ms, characters);
|
| 705 |
-
// Clipboard.SetData("TextEditorCustomFormat", ms.ToArray());
|
| 706 |
-
// }
|
| 707 |
-
// 序列化
|
| 708 |
string json = Newtonsoft.Json.JsonConvert.SerializeObject(characters);
|
| 709 |
-
|
| 710 |
}
|
| 711 |
}
|
| 712 |
catch (Exception ex)
|
| 713 |
{
|
| 714 |
System.Diagnostics.Debug.WriteLine($"复制到剪贴板时出错: {ex.Message}");
|
| 715 |
}
|
|
|
|
|
|
|
|
|
|
| 716 |
}
|
| 717 |
e.Handled = true;
|
| 718 |
}
|
|
@@ -725,9 +724,13 @@ namespace WpfEditor
|
|
| 725 |
{
|
| 726 |
_isCut = true;
|
| 727 |
|
| 728 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
|
| 730 |
-
// 序列化TextCharacter列表并保存
|
| 731 |
try
|
| 732 |
{
|
| 733 |
var characters = GetSelectedTextCharacters();
|
|
@@ -735,13 +738,16 @@ namespace WpfEditor
|
|
| 735 |
{
|
| 736 |
// 序列化
|
| 737 |
string json = Newtonsoft.Json.JsonConvert.SerializeObject(characters);
|
| 738 |
-
|
| 739 |
}
|
| 740 |
}
|
| 741 |
catch (Exception ex)
|
| 742 |
{
|
| 743 |
System.Diagnostics.Debug.WriteLine($"剪切到剪贴板时出错: {ex.Message}");
|
| 744 |
}
|
|
|
|
|
|
|
|
|
|
| 745 |
|
| 746 |
DeleteSelection();
|
| 747 |
InvalidateVisual();
|
|
@@ -804,46 +810,46 @@ namespace WpfEditor
|
|
| 804 |
|
| 805 |
// 如果是复制的普通文本
|
| 806 |
if (!customDataPasted && Clipboard.ContainsText())
|
| 807 |
-
{
|
| 808 |
-
string text = Clipboard.GetText();
|
| 809 |
-
if (text.Length > 0)
|
| 810 |
-
{
|
| 811 |
-
//List<TextCharacter> characters = new List<TextCharacter>();
|
| 812 |
-
|
| 813 |
-
//TextCharacter c = null;
|
| 814 |
-
//if (characters_selected.Count > 0)
|
| 815 |
-
//{
|
| 816 |
-
// c = characters_selected[0];
|
| 817 |
-
//}
|
| 818 |
-
|
| 819 |
-
//for (int i = 0; i < text.Length;)
|
| 820 |
-
//{
|
| 821 |
-
// Rune rune = Rune.GetRuneAt(text, i);
|
| 822 |
-
|
| 823 |
-
// var chr = new TextCharacter(
|
| 824 |
-
// rune,
|
| 825 |
-
// c.guid,
|
| 826 |
-
// c.x,
|
| 827 |
-
// c.y,
|
| 828 |
-
// c.w,
|
| 829 |
-
// c.h,
|
| 830 |
-
// c.ImageMD5
|
| 831 |
// );
|
| 832 |
-
// characters.Add(chr);
|
| 833 |
-
|
| 834 |
-
// i += rune.Utf16SequenceLength;
|
| 835 |
-
//}
|
| 836 |
-
|
| 837 |
//if (characters != null && characters.Count > 0)
|
| 838 |
//{
|
| 839 |
// InsertTextCharacters(characters);
|
| 840 |
-
//}
|
| 841 |
-
|
| 842 |
-
InsertTextCharacters(text);
|
| 843 |
-
|
| 844 |
-
}
|
| 845 |
-
}
|
| 846 |
-
|
| 847 |
if (_isCut)
|
| 848 |
{
|
| 849 |
Clipboard.Clear();
|
|
@@ -851,63 +857,63 @@ namespace WpfEditor
|
|
| 851 |
}
|
| 852 |
|
| 853 |
InvalidateVisual();
|
| 854 |
-
}
|
| 855 |
-
|
| 856 |
-
if (HasSelection())
|
| 857 |
-
{
|
| 858 |
-
DeleteSelection();
|
| 859 |
}
|
| 860 |
|
| 861 |
e.Handled = true;
|
| 862 |
-
}
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
public void InsertTextCharacters(string text)
|
| 866 |
-
{
|
| 867 |
-
if (text.Length > 0)
|
| 868 |
-
{
|
| 869 |
-
List<TextCharacter> characters = new List<TextCharacter>();
|
| 870 |
-
|
| 871 |
-
TextCharacter c = null;
|
| 872 |
-
if (HasSelection())
|
| 873 |
-
{
|
| 874 |
-
List<TextCharacter> characters_selected = GetSelectedTextCharacters();
|
| 875 |
-
if (characters_selected.Count > 0)
|
| 876 |
-
{
|
| 877 |
-
c = characters_selected[0];
|
| 878 |
-
}
|
| 879 |
-
} else
|
| 880 |
-
{
|
| 881 |
-
c = GetCharacterAfterCursor();
|
| 882 |
-
if (c == null)
|
| 883 |
-
{
|
| 884 |
-
c = GetCharacterBeforeCursor();
|
| 885 |
-
}
|
| 886 |
-
}
|
| 887 |
-
|
| 888 |
-
for (int i = 0; i < text.Length;)
|
| 889 |
-
{
|
| 890 |
-
Rune rune = Rune.GetRuneAt(text, i);
|
| 891 |
-
|
| 892 |
-
var chr = new TextCharacter(
|
| 893 |
-
rune,
|
| 894 |
-
c.guid,
|
| 895 |
-
c.x,
|
| 896 |
-
c.y,
|
| 897 |
-
c.w,
|
| 898 |
-
c.h,
|
| 899 |
-
c.ImageMD5
|
| 900 |
-
);
|
| 901 |
-
characters.Add(chr);
|
| 902 |
-
|
| 903 |
-
i += rune.Utf16SequenceLength;
|
| 904 |
-
}
|
| 905 |
-
|
| 906 |
-
if (characters != null && characters.Count > 0)
|
| 907 |
-
{
|
| 908 |
-
InsertTextCharacters(characters);
|
| 909 |
-
}
|
| 910 |
-
}
|
| 911 |
}
|
| 912 |
|
| 913 |
private void InsertTextCharacters(List<TextCharacter> characters)
|
|
@@ -1055,19 +1061,19 @@ namespace WpfEditor
|
|
| 1055 |
string guid = item2["guid"].Value<string>();
|
| 1056 |
int isDeleted = item2["isDeleted"].Value<int>();
|
| 1057 |
// 就算是阿里云的 json ,也要先给它加入 guid
|
| 1058 |
-
//if (item2["guid"] != null)
|
| 1059 |
-
//{
|
| 1060 |
-
// guid = item2["guid"].Value<string>();
|
| 1061 |
-
//} else
|
| 1062 |
-
//{
|
| 1063 |
-
// guid = Guid.NewGuid().ToString();
|
| 1064 |
-
//}
|
| 1065 |
-
|
| 1066 |
-
if (isDeleted == 1)
|
| 1067 |
-
{
|
| 1068 |
-
continue;
|
| 1069 |
-
}
|
| 1070 |
-
|
| 1071 |
int x = item2["x"].Value<int>();
|
| 1072 |
int y = item2["y"].Value<int>();
|
| 1073 |
int w = item2["w"].Value<int>();
|
|
@@ -1105,8 +1111,8 @@ namespace WpfEditor
|
|
| 1105 |
|
| 1106 |
// 触发文本改变事件
|
| 1107 |
OnTextChanged();
|
| 1108 |
-
}
|
| 1109 |
-
|
| 1110 |
public void InsertText(JObject jsn, string md5)
|
| 1111 |
{
|
| 1112 |
_undoBuffer.Clear();
|
|
@@ -1122,7 +1128,7 @@ namespace WpfEditor
|
|
| 1122 |
int height = jsn.Value<int>("height");
|
| 1123 |
|
| 1124 |
var prism_wordsInfo = jsn["prism_wordsInfo"].Value<JArray>();
|
| 1125 |
-
foreach (var item in prism_wordsInfo)
|
| 1126 |
{
|
| 1127 |
JArray charInfo = item["charInfo"].Value<JArray>();
|
| 1128 |
string line_word = item["word"].Value<string>();
|
|
@@ -1131,15 +1137,15 @@ namespace WpfEditor
|
|
| 1131 |
foreach (var item2 in charInfo)
|
| 1132 |
{
|
| 1133 |
string oneChar = item2["word"].Value<string>();
|
| 1134 |
-
string guid = item2["guid"].Value<string>();
|
| 1135 |
-
// 就算是阿里云的 json ,也要先给它加入 guid
|
| 1136 |
-
//if (item2["guid"] != null)
|
| 1137 |
-
//{
|
| 1138 |
-
// guid = item2["guid"].Value<string>();
|
| 1139 |
-
//} else
|
| 1140 |
-
//{
|
| 1141 |
-
// guid = Guid.NewGuid().ToString();
|
| 1142 |
-
//}
|
| 1143 |
int x = item2["x"].Value<int>();
|
| 1144 |
int y = item2["y"].Value<int>();
|
| 1145 |
int w = item2["w"].Value<int>();
|
|
@@ -1620,12 +1626,12 @@ namespace WpfEditor
|
|
| 1620 |
DeleteSelection();
|
| 1621 |
}
|
| 1622 |
else if (_cursorColumn < _lines[_cursorLine].Characters.Count)
|
| 1623 |
-
{
|
| 1624 |
-
// 删除当前字符
|
| 1625 |
TextCharacter c = _lines[_cursorLine].Characters[_cursorColumn];
|
| 1626 |
-
if (c.guid != "")
|
| 1627 |
-
{
|
| 1628 |
-
_dic_deleted_char[c.guid] = c.Character.Value.ToString();
|
| 1629 |
}
|
| 1630 |
_lines[_cursorLine].Characters.RemoveAt(_cursorColumn);
|
| 1631 |
_textChanged = true;
|
|
@@ -1652,9 +1658,9 @@ namespace WpfEditor
|
|
| 1652 |
// 删除前一个字符
|
| 1653 |
_cursorColumn--;
|
| 1654 |
TextCharacter c = _lines[_cursorLine].Characters[_cursorColumn];
|
| 1655 |
-
if (c.guid != "")
|
| 1656 |
-
{
|
| 1657 |
-
_dic_deleted_char[c.guid] = c.Character.Value.ToString();
|
| 1658 |
}
|
| 1659 |
_lines[_cursorLine].Characters.RemoveAt(_cursorColumn);
|
| 1660 |
_textChanged = true;
|
|
@@ -2121,8 +2127,8 @@ namespace WpfEditor
|
|
| 2121 |
}
|
| 2122 |
}
|
| 2123 |
return null; // 如果没有找到字符,返回null
|
| 2124 |
-
}
|
| 2125 |
-
|
| 2126 |
private TextCharacter GetCharacterBeforeCursor()
|
| 2127 |
{
|
| 2128 |
if (_cursorLine >= 0 && _cursorLine < _lines.Count)
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
public void ShowDraggableImageControl(Mat image, Mat image_orig)
|
| 59 |
+
{
|
| 60 |
var mainWindow = Window.GetWindow(this) as MainWindow;
|
| 61 |
|
| 62 |
// 将Mat转换为BitmapSource
|
|
|
|
| 176 |
border.ContextMenu = contextMenu;
|
| 177 |
|
| 178 |
// 显示窗口
|
| 179 |
+
_imageWindow.Show(); // 单行文本图
|
| 180 |
+
|
| 181 |
+
// 根据图片大小调整窗口尺寸
|
| 182 |
AdjustWindowSizeBasedOnImage(_imageWindow, bitmapSource.PixelWidth, bitmapSource.PixelHeight);
|
| 183 |
|
| 184 |
// 设置初始位置(居中显示)
|
|
|
|
| 187 |
_imageWindow.Left = 0; // mainWindow.Left + (mainWindow.Width - _imageWindow.ActualWidth) / 2;
|
| 188 |
_imageWindow.Top = mainWindow.Top + (mainWindow.Height - _imageWindow.ActualHeight) / 2;
|
| 189 |
}
|
| 190 |
+
|
| 191 |
+
if (mainWindow != null)
|
| 192 |
+
{
|
| 193 |
+
if (true || mainWindow.ImageViewer.Source == null)
|
| 194 |
+
{
|
| 195 |
+
mainWindow.ShowImageInPanel(bitmapSource2); // 全图
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
}
|
| 201 |
|
| 202 |
// 根据图片大小调整窗口尺寸的辅助方法
|
|
|
|
| 482 |
if (!IsReadOnly)
|
| 483 |
{
|
| 484 |
//InsertText(e.Text);
|
| 485 |
+
InsertTextCharacters(e.Text);
|
| 486 |
+
|
| 487 |
+
// 标记文本已更改
|
| 488 |
+
_textChanged = true;
|
| 489 |
+
|
| 490 |
+
// 触发文本改变事件
|
| 491 |
+
OnTextChanged();
|
| 492 |
+
|
| 493 |
+
// 触发光标位置改变事件
|
| 494 |
+
OnCursorPositionChanged(_cursorLine, _cursorColumn);
|
| 495 |
+
|
| 496 |
+
// 重绘编辑器
|
| 497 |
InvalidateVisual();
|
| 498 |
|
| 499 |
e.Handled = true;
|
|
|
|
| 618 |
// InvalidateVisual();
|
| 619 |
//}
|
| 620 |
|
| 621 |
+
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
| 622 |
+
{
|
| 623 |
+
base.OnMouseLeftButtonDown(e);
|
| 624 |
Focus();
|
| 625 |
Point position = e.GetPosition(this);
|
| 626 |
SetCursorPositionFromPoint(position);
|
|
|
|
| 631 |
else
|
| 632 |
{
|
| 633 |
UpdateSelection();
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
// 图片中框选光标后面的第一个字符
|
| 637 |
if (e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)
|
| 638 |
{
|
| 639 |
showCurrChar();
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
e.Handled = true;
|
| 643 |
+
InvalidateVisual();
|
| 644 |
}
|
| 645 |
+
|
| 646 |
+
// 重写右键按下事件
|
| 647 |
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
|
| 648 |
{
|
| 649 |
base.OnMouseRightButtonDown(e);
|
|
|
|
| 688 |
if (HasSelection())
|
| 689 |
{
|
| 690 |
_isCut = false;
|
|
|
|
|
|
|
| 691 |
|
| 692 |
+
// 创建DataObject来同时设置多种格式
|
| 693 |
+
DataObject dataObject = new DataObject();
|
| 694 |
+
|
| 695 |
+
// 设置标准文本格式(供其他程序使用)
|
| 696 |
+
dataObject.SetText(GetSelectedText());
|
| 697 |
+
|
| 698 |
+
// 序列化TextCharacter列表并保存自定义格式
|
| 699 |
try
|
| 700 |
{
|
| 701 |
var characters = GetSelectedTextCharacters();
|
| 702 |
if (characters.Count > 0)
|
| 703 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
string json = Newtonsoft.Json.JsonConvert.SerializeObject(characters);
|
| 705 |
+
dataObject.SetData("TextEditorCustomFormat", json);
|
| 706 |
}
|
| 707 |
}
|
| 708 |
catch (Exception ex)
|
| 709 |
{
|
| 710 |
System.Diagnostics.Debug.WriteLine($"复制到剪贴板时出错: {ex.Message}");
|
| 711 |
}
|
| 712 |
+
|
| 713 |
+
// 一次性设置到剪贴板
|
| 714 |
+
Clipboard.SetDataObject(dataObject);
|
| 715 |
}
|
| 716 |
e.Handled = true;
|
| 717 |
}
|
|
|
|
| 724 |
{
|
| 725 |
_isCut = true;
|
| 726 |
|
| 727 |
+
// 创建DataObject来同时设置多种格式
|
| 728 |
+
DataObject dataObject = new DataObject();
|
| 729 |
+
|
| 730 |
+
// 设置标准文本格式(供其他程序使用)
|
| 731 |
+
dataObject.SetText(GetSelectedText());
|
| 732 |
|
| 733 |
+
// 序列化TextCharacter列表并保存自定义格式
|
| 734 |
try
|
| 735 |
{
|
| 736 |
var characters = GetSelectedTextCharacters();
|
|
|
|
| 738 |
{
|
| 739 |
// 序列化
|
| 740 |
string json = Newtonsoft.Json.JsonConvert.SerializeObject(characters);
|
| 741 |
+
dataObject.SetData("TextEditorCustomFormat", json);
|
| 742 |
}
|
| 743 |
}
|
| 744 |
catch (Exception ex)
|
| 745 |
{
|
| 746 |
System.Diagnostics.Debug.WriteLine($"剪切到剪贴板时出错: {ex.Message}");
|
| 747 |
}
|
| 748 |
+
|
| 749 |
+
// 一次性设置到剪贴板
|
| 750 |
+
Clipboard.SetDataObject(dataObject);
|
| 751 |
|
| 752 |
DeleteSelection();
|
| 753 |
InvalidateVisual();
|
|
|
|
| 810 |
|
| 811 |
// 如果是复制的普通文本
|
| 812 |
if (!customDataPasted && Clipboard.ContainsText())
|
| 813 |
+
{
|
| 814 |
+
string text = Clipboard.GetText();
|
| 815 |
+
if (text.Length > 0)
|
| 816 |
+
{
|
| 817 |
+
//List<TextCharacter> characters = new List<TextCharacter>();
|
| 818 |
+
|
| 819 |
+
//TextCharacter c = null;
|
| 820 |
+
//if (characters_selected.Count > 0)
|
| 821 |
+
//{
|
| 822 |
+
// c = characters_selected[0];
|
| 823 |
+
//}
|
| 824 |
+
|
| 825 |
+
//for (int i = 0; i < text.Length;)
|
| 826 |
+
//{
|
| 827 |
+
// Rune rune = Rune.GetRuneAt(text, i);
|
| 828 |
+
|
| 829 |
+
// var chr = new TextCharacter(
|
| 830 |
+
// rune,
|
| 831 |
+
// c.guid,
|
| 832 |
+
// c.x,
|
| 833 |
+
// c.y,
|
| 834 |
+
// c.w,
|
| 835 |
+
// c.h,
|
| 836 |
+
// c.ImageMD5
|
| 837 |
// );
|
| 838 |
+
// characters.Add(chr);
|
| 839 |
+
|
| 840 |
+
// i += rune.Utf16SequenceLength;
|
| 841 |
+
//}
|
| 842 |
+
|
| 843 |
//if (characters != null && characters.Count > 0)
|
| 844 |
//{
|
| 845 |
// InsertTextCharacters(characters);
|
| 846 |
+
//}
|
| 847 |
+
|
| 848 |
+
InsertTextCharacters(text);
|
| 849 |
+
|
| 850 |
+
}
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
if (_isCut)
|
| 854 |
{
|
| 855 |
Clipboard.Clear();
|
|
|
|
| 857 |
}
|
| 858 |
|
| 859 |
InvalidateVisual();
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
if (HasSelection())
|
| 863 |
+
{
|
| 864 |
+
DeleteSelection();
|
| 865 |
}
|
| 866 |
|
| 867 |
e.Handled = true;
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
public void InsertTextCharacters(string text)
|
| 872 |
+
{
|
| 873 |
+
if (text.Length > 0)
|
| 874 |
+
{
|
| 875 |
+
List<TextCharacter> characters = new List<TextCharacter>();
|
| 876 |
+
|
| 877 |
+
TextCharacter c = null;
|
| 878 |
+
if (HasSelection())
|
| 879 |
+
{
|
| 880 |
+
List<TextCharacter> characters_selected = GetSelectedTextCharacters();
|
| 881 |
+
if (characters_selected.Count > 0)
|
| 882 |
+
{
|
| 883 |
+
c = characters_selected[0];
|
| 884 |
+
}
|
| 885 |
+
} else
|
| 886 |
+
{
|
| 887 |
+
c = GetCharacterAfterCursor();
|
| 888 |
+
if (c == null)
|
| 889 |
+
{
|
| 890 |
+
c = GetCharacterBeforeCursor();
|
| 891 |
+
}
|
| 892 |
+
}
|
| 893 |
+
|
| 894 |
+
for (int i = 0; i < text.Length;)
|
| 895 |
+
{
|
| 896 |
+
Rune rune = Rune.GetRuneAt(text, i);
|
| 897 |
+
|
| 898 |
+
var chr = new TextCharacter(
|
| 899 |
+
rune,
|
| 900 |
+
c.guid,
|
| 901 |
+
c.x,
|
| 902 |
+
c.y,
|
| 903 |
+
c.w,
|
| 904 |
+
c.h,
|
| 905 |
+
c.ImageMD5
|
| 906 |
+
);
|
| 907 |
+
characters.Add(chr);
|
| 908 |
+
|
| 909 |
+
i += rune.Utf16SequenceLength;
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
if (characters != null && characters.Count > 0)
|
| 913 |
+
{
|
| 914 |
+
InsertTextCharacters(characters);
|
| 915 |
+
}
|
| 916 |
+
}
|
| 917 |
}
|
| 918 |
|
| 919 |
private void InsertTextCharacters(List<TextCharacter> characters)
|
|
|
|
| 1061 |
string guid = item2["guid"].Value<string>();
|
| 1062 |
int isDeleted = item2["isDeleted"].Value<int>();
|
| 1063 |
// 就算是阿里云的 json ,也要先给它加入 guid
|
| 1064 |
+
//if (item2["guid"] != null)
|
| 1065 |
+
//{
|
| 1066 |
+
// guid = item2["guid"].Value<string>();
|
| 1067 |
+
//} else
|
| 1068 |
+
//{
|
| 1069 |
+
// guid = Guid.NewGuid().ToString();
|
| 1070 |
+
//}
|
| 1071 |
+
|
| 1072 |
+
if (isDeleted == 1)
|
| 1073 |
+
{
|
| 1074 |
+
continue;
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
int x = item2["x"].Value<int>();
|
| 1078 |
int y = item2["y"].Value<int>();
|
| 1079 |
int w = item2["w"].Value<int>();
|
|
|
|
| 1111 |
|
| 1112 |
// 触发文本改变事件
|
| 1113 |
OnTextChanged();
|
| 1114 |
+
}
|
| 1115 |
+
|
| 1116 |
public void InsertText(JObject jsn, string md5)
|
| 1117 |
{
|
| 1118 |
_undoBuffer.Clear();
|
|
|
|
| 1128 |
int height = jsn.Value<int>("height");
|
| 1129 |
|
| 1130 |
var prism_wordsInfo = jsn["prism_wordsInfo"].Value<JArray>();
|
| 1131 |
+
foreach (var item in prism_wordsInfo)
|
| 1132 |
{
|
| 1133 |
JArray charInfo = item["charInfo"].Value<JArray>();
|
| 1134 |
string line_word = item["word"].Value<string>();
|
|
|
|
| 1137 |
foreach (var item2 in charInfo)
|
| 1138 |
{
|
| 1139 |
string oneChar = item2["word"].Value<string>();
|
| 1140 |
+
string guid = item2["guid"].Value<string>();
|
| 1141 |
+
// 就算是阿里云的 json ,也要先给它加入 guid
|
| 1142 |
+
//if (item2["guid"] != null)
|
| 1143 |
+
//{
|
| 1144 |
+
// guid = item2["guid"].Value<string>();
|
| 1145 |
+
//} else
|
| 1146 |
+
//{
|
| 1147 |
+
// guid = Guid.NewGuid().ToString();
|
| 1148 |
+
//}
|
| 1149 |
int x = item2["x"].Value<int>();
|
| 1150 |
int y = item2["y"].Value<int>();
|
| 1151 |
int w = item2["w"].Value<int>();
|
|
|
|
| 1626 |
DeleteSelection();
|
| 1627 |
}
|
| 1628 |
else if (_cursorColumn < _lines[_cursorLine].Characters.Count)
|
| 1629 |
+
{
|
| 1630 |
+
// 删除当前字符
|
| 1631 |
TextCharacter c = _lines[_cursorLine].Characters[_cursorColumn];
|
| 1632 |
+
if (c.guid != "")
|
| 1633 |
+
{
|
| 1634 |
+
_dic_deleted_char[c.guid] = c.Character.Value.ToString();
|
| 1635 |
}
|
| 1636 |
_lines[_cursorLine].Characters.RemoveAt(_cursorColumn);
|
| 1637 |
_textChanged = true;
|
|
|
|
| 1658 |
// 删除前一个字符
|
| 1659 |
_cursorColumn--;
|
| 1660 |
TextCharacter c = _lines[_cursorLine].Characters[_cursorColumn];
|
| 1661 |
+
if (c.guid != "")
|
| 1662 |
+
{
|
| 1663 |
+
_dic_deleted_char[c.guid] = c.Character.Value.ToString();
|
| 1664 |
}
|
| 1665 |
_lines[_cursorLine].Characters.RemoveAt(_cursorColumn);
|
| 1666 |
_textChanged = true;
|
|
|
|
| 2127 |
}
|
| 2128 |
}
|
| 2129 |
return null; // 如果没有找到字符,返回null
|
| 2130 |
+
}
|
| 2131 |
+
|
| 2132 |
private TextCharacter GetCharacterBeforeCursor()
|
| 2133 |
{
|
| 2134 |
if (_cursorLine >= 0 && _cursorLine < _lines.Count)
|
src/WpfEditor/TreeMenuPage.xaml
CHANGED
|
@@ -74,8 +74,8 @@
|
|
| 74 |
<TreeViewItem Header="智能录入" IsExpanded="True">
|
| 75 |
<TreeViewItem Header="图片识别" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="ImageOCR"/>
|
| 76 |
<TreeViewItem Header="整理校对" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="ReviseEdit"/>
|
| 77 |
-
<TreeViewItem Header="
|
| 78 |
-
<TreeViewItem Header="
|
| 79 |
</TreeViewItem>
|
| 80 |
|
| 81 |
<TreeViewItem Header="编辑操作" IsExpanded="True">
|
|
|
|
| 74 |
<TreeViewItem Header="智能录入" IsExpanded="True">
|
| 75 |
<TreeViewItem Header="图片识别" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="ImageOCR"/>
|
| 76 |
<TreeViewItem Header="整理校对" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="ReviseEdit"/>
|
| 77 |
+
<TreeViewItem Header="目录拆解" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="MenuSplit"/>
|
| 78 |
+
<TreeViewItem Header="内容录入" MouseDoubleClick="TreeItem_MouseDoubleClick" Tag="ContenInto"/>
|
| 79 |
</TreeViewItem>
|
| 80 |
|
| 81 |
<TreeViewItem Header="编辑操作" IsExpanded="True">
|