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
// Editor // Editor
// //
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.VScrollBar);
this.Controls.Add(this.header); this.Controls.Add(this.header);
this.Controls.Add(this.textView); this.Controls.Add(this.textView);
this.Controls.Add(this.hexView); this.Controls.Add(this.hexView);
this.Controls.Add(this.side); this.Controls.Add(this.side);
this.Controls.Add(this.VScrollBar);
this.DoubleBuffered = true; this.DoubleBuffered = true;
this.MinimumSize = new System.Drawing.Size(1, 1); this.MinimumSize = new System.Drawing.Size(1, 1);
this.Name = "Editor"; this.Name = "Editor";

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

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

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

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

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

@ -81,6 +81,16 @@ namespace HexEditor.Util
return buffer.GetBytes(Math.Min(Start, End), Math.Abs(End - Start)); 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> /// <summary>
/// Cleares the selection (no text is altered) /// Cleares the selection (no text is altered)
/// </summary> /// </summary>

Loading…
Cancel
Save