public static void Backspace(HexEditorData data) { if (data.IsSomethingSelected) { data.DeleteSelection(); return; } if (data.Caret.Offset == 0) { return; } data.ByteBuffer.Remove(data.Caret.Offset - 1, 1); data.Caret.Offset--; }
public static void Delete(HexEditorData data) { if (data.IsSomethingSelected) { data.DeleteSelection(); return; } if (data.Caret.Offset >= data.Length) { return; } data.ByteBuffer.Remove(data.Caret.Offset, 1); data.UpdateLine(data.Caret.Line); }
void InsertCharacter(uint unicodeChar) { char ch = (char)unicodeChar; if (HexEditorData.IsSomethingSelected) { HexEditorData.DeleteSelection(); } if (HexEditorData.Caret.InTextEditor) { if ((char.IsLetterOrDigit(ch) || char.IsPunctuation(ch) || ch == ' ') && unicodeChar <= 255) { if (HexEditorData.Caret.IsInsertMode) { HexEditorData.Insert(HexEditorData.Caret.Offset, (byte)unicodeChar); } else { HexEditorData.Replace(HexEditorData.Caret.Offset, 1, (byte)unicodeChar); } Editor.Margins.ForEach(margin => margin.PurgeLayoutCache()); CaretMoveActions.Right(HexEditorData); } } else { string hex = "0123456789ABCDEF"; int idx = hex.IndexOf(char.ToUpper(ch)); if (idx >= 0) { if (HexEditorData.Caret.Offset >= HexEditorData.Length) { HexEditorData.Insert(HexEditorData.Length, 0); } if (HexEditorData.Caret.IsInsertMode && HexEditorData.Caret.SubPosition == 0) { HexEditorData.Insert(HexEditorData.Caret.Offset, (byte)(idx * 0x10)); } else { byte cur = HexEditorData.GetByte(HexEditorData.Caret.Offset); int newByte = HexEditorData.Caret.SubPosition == 0 ? cur & 0xF | idx * 0x10 : cur & 0xF0 | idx; HexEditorData.Replace(HexEditorData.Caret.Offset, 1, (byte)newByte); } Editor.Margins.ForEach(margin => margin.PurgeLayoutCache()); CaretMoveActions.Right(HexEditorData); } } }