Browse Source

fixed bugs in hex editor related to "split view"

filemodels
Siegfried Pammer 11 years ago
parent
commit
5a2177dbc5
  1. 2
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs
  2. 19
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs
  3. 1
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs
  4. 10
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/SelectionManager.cs

2
src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs generated

@ -112,11 +112,11 @@ namespace HexEditor @@ -112,11 +112,11 @@ namespace HexEditor
// Editor
//
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.VScrollBar);
this.Controls.Add(this.header);
this.Controls.Add(this.textView);
this.Controls.Add(this.hexView);
this.Controls.Add(this.side);
this.Controls.Add(this.VScrollBar);
this.DoubleBuffered = true;
this.MinimumSize = new System.Drawing.Size(1, 1);
this.Name = "Editor";

19
src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs

@ -136,6 +136,12 @@ namespace HexEditor @@ -136,6 +136,12 @@ namespace HexEditor
void BufferChanged(object sender, EventArgs e)
{
if (!Focused) {
selection.ValidateSelection();
caret.Offset = Math.Max(0, Math.Min(caret.Offset, buffer.BufferSize));
Point pos = GetPositionForOffset(caret.Offset, charwidth);
caret.SetToPosition(pos);
}
Invalidate();
OnDocumentChanged(EventArgs.Empty);
}
@ -1301,6 +1307,7 @@ namespace HexEditor @@ -1301,6 +1307,7 @@ namespace HexEditor
break;
case Keys.Back:
e.Handled = true;
e.SuppressKeyPress = true;
if (hexinputmode) return;
if (selection.HasSomethingSelected) {
byte[] bytes = selection.GetSelectionBytes();
@ -1314,8 +1321,7 @@ namespace HexEditor @@ -1314,8 +1321,7 @@ namespace HexEditor
} else {
byte b = buffer.GetByte(caret.Offset - 1);
if (buffer.RemoveByte(caret.Offset - 1))
{
if (buffer.RemoveByte(caret.Offset - 1)) {
if (caret.Offset > -1) caret.Offset--;
if (GetLineForOffset(caret.Offset) < topline) topline = GetLineForOffset(caret.Offset);
if (GetLineForOffset(caret.Offset) > topline + GetMaxVisibleLines() - 2) topline = GetLineForOffset(caret.Offset) - GetMaxVisibleLines() + 2;
@ -1328,6 +1334,7 @@ namespace HexEditor @@ -1328,6 +1334,7 @@ namespace HexEditor
break;
case Keys.Delete:
e.Handled = true;
e.SuppressKeyPress = true;
if (hexinputmode) return;
if (selection.HasSomethingSelected) {
byte[] old = selection.GetSelectionBytes();
@ -1353,6 +1360,7 @@ namespace HexEditor @@ -1353,6 +1360,7 @@ namespace HexEditor
case Keys.CapsLock:
case Keys.ShiftKey:
case Keys.ControlKey:
case Keys.Enter:
break;
case Keys.Tab:
if (activeView == hexView) {
@ -1405,6 +1413,7 @@ namespace HexEditor @@ -1405,6 +1413,7 @@ namespace HexEditor
if (activeView == hexView) {
ProcessHexInput(e);
e.Handled = true;
e.SuppressKeyPress = true;
return;
}
@ -1773,7 +1782,6 @@ namespace HexEditor @@ -1773,7 +1782,6 @@ namespace HexEditor
/// <summary>
/// Calculates the max possible bytes per line.
/// </summary>
/// <returns>Int32, containing the result</returns>
internal int CalculateMaxBytesPerLine()
{
int width = Width - side.Width - 90;
@ -1836,6 +1844,8 @@ namespace HexEditor @@ -1836,6 +1844,8 @@ namespace HexEditor
if (offset < buffer.BufferSize) {
return offset;
} else {
hexinputmodepos = 0;
hexinputmode = false;
return buffer.BufferSize;
}
}
@ -1852,7 +1862,8 @@ namespace HexEditor @@ -1852,7 +1862,8 @@ namespace HexEditor
int line = (int)(offset / BytesPerLine) - topline;
int pline = line * fontheight - 1 * (line - 1) - 1;
int col = (offset % BytesPerLine) * underscorewidth * charwidth + 4;
if (hexinputmode && !selectionmode && !selection.HasSomethingSelected && insertmode) col += (hexinputmodepos * underscorewidth);
if (hexinputmode && !selectionmode && !selection.HasSomethingSelected && insertmode)
col += (hexinputmodepos * underscorewidth);
return new Point(col, pline);
}

1
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs

@ -153,6 +153,7 @@ namespace HexEditor.Util @@ -153,6 +153,7 @@ namespace HexEditor.Util
if ((offset < buffer.Count) & (offset > -1)) {
buffer.RemoveAt(offset);
file.MakeDirty(HexEditFileModelProvider.Instance);
OnBufferChanged(EventArgs.Empty);
return true;
}
return false;

10
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/SelectionManager.cs

@ -80,6 +80,16 @@ namespace HexEditor.Util @@ -80,6 +80,16 @@ namespace HexEditor.Util
{
return buffer.GetBytes(Math.Min(Start, End), Math.Abs(End - Start));
}
public void ValidateSelection()
{
int start = Math.Min(this.start, this.end);
int end = Math.Max(this.start, this.end);
start = Math.Min(Math.Max(0, start), buffer.BufferSize);
end = Math.Min(Math.Max(0, end), buffer.BufferSize);
this.start = start;
this.end = end;
}
/// <summary>
/// Cleares the selection (no text is altered)

Loading…
Cancel
Save