private void MoveCharPosDown(Position pos) { if (pos.Line == _lines.Length - 1) return; pos.Line += 1; if (_lines[pos.Line].Length - 1 < pos.Column) { pos.Column = _lines[pos.Line].Length - 1; if (pos.Column < 0) pos.Column = 0; } }
private void MoveCharPosToLeft(Position pos) { if (pos.Column - 1 >= 0) { pos.Column -= 1; } else if (pos.Line - 1 >= 0) { pos.Line -= 1; pos.Column = _lines[_selection.End.Line].Length - 1; } }
private void MoveCharPosUp(Position pos) { if (pos.Line == 0) return; pos.Line -= 1; if (_lines[pos.Line].Length - 1 < pos.Column) { pos.Column = _lines[pos.Line].Length - 1; } }
private void MoveCharPosToRight(Position pos) { if ((pos.Line < _lines.Length - 1 && pos.Column + 1 <= _lines[pos.Line].Length - 1) || (pos.Line == _lines.Length - 1 && pos.Column + 1 <= _lines[pos.Line].Length)) { pos.Column += 1; } else if (pos.Line + 1 <= _lines.Length - 1) { pos.Column = 0; pos.Line += 1; } }
private void SetCharPosToNearestToPoint(Position pos, int x, int y, int shiftX, int shiftY) { var line = Math.Max((y - shiftY)/_font.Height, 0); var column = (int) Math.Max((x - DockWidth - shiftX + 3 - OffsetFromDock)/_charWidth, 0); if (line > _lines.Length - 1) { pos.Line = _lines.Length - 1; } else { pos.Line = line; } if (pos.Line < _lines.Length - 1) { if (column <= _lines[pos.Line].Length - 1) { pos.Column = column; } else { pos.Column = _lines[pos.Line].Length - 1; } } else { if (column <= _lines[pos.Line].Length - 1) { pos.Column = column; } else { pos.Column = _lines[pos.Line].Length; } } }
private void MoveCharPosToLineEnd(Position pos) { pos.Column = _lines[pos.Line].Length - 1; if (pos.Line == _lines.Length - 1) pos.Column += 1; }
private void MoveCharPosToLineStart(Position pos) { pos.Column = 0; }
private int CharPosToIndex(Position p) { var cnt = 0; for (var i = 0; i < p.Line; ++i) { cnt += _lines[i].Length + 1; } cnt += p.Column; return cnt; }