void myTextbox1_MyTaskEvent(object sender, TaskEventArgs e) { myDefaultTextbox1.Text = e.task.ToString() + Environment.NewLine + myDefaultTextbox1.Text; }
/// <summary> /// 文字列を削除 /// </summary> /// <param name="nLine"></param> /// <param name="index">開始点</param> /// <param name="count">削除する長さ</param> public void Delete(int nLine, int index, int count) { if (index < 0) { // 行の先頭でBackspaceを押すとここに来る。 // (0, 0)であれば無視。 // それ以外であれば前の行の改行コードを消して、前の行と結合する。 if (nLine == 0) { // 無視する。 return; } else { CurrentPhysicalPosition = new PhysicalPosition(nLine - 1, list[nLine - 1].Length); MyLine line = new MyLine(list[nLine - 1].TextWithoutReturnValue + list[nLine].TextWithoutReturnValue, list[nLine].ReturnCode); list[nLine - 1] = line; list.RemoveAt(nLine); Invalidate(); } } else { // 現状、0点で実行すると-1になるバグあり MyLine line = list[nLine]; line.Delete(index, count); CurrentPhysicalPosition = new PhysicalPosition(nLine, index); } // 履歴に登録し、タスクイベントを起こす Task task = new Delete(); task.fromLine = nLine; task.fromPos = index; task.length = count; history.Add(task); if (MyTaskEvent != null) { TaskEventArgs args = new TaskEventArgs(); args.task = task; MyTaskEvent(this, args); } Invalidate(); }
/// <summary> /// 任意の位置に文字列を挿入 /// </summary> /// <param name="nLine">Line number. 0 origin</param> /// <param name="pos"></param> /// <param name="str"></param> public Task Insert(int nLine, int pos, string str) { //nLineがまだ存在しない行番号だった場合に備えて、その行までの存在しない行を全て作成 // 例えば、現在0-4行目が存在、8行目に文字を挿入する場合、 // 5-8行目を作成する。 for (int i = list.Count; i < nLine + 1; i++) { MyLine newLine = new MyLine(); list.Add(newLine); } MyLine line = list[nLine]; line.Insert(pos, str); // 任意の位置に挿入するのだから、キャレットとは違う位置に行を増やさないように挿入した時にはキャレットに影響は無い。従って、現状ではバグがある。 CurrentPhysicalPosition = new PhysicalPosition(CurrentPhysicalPosition.Line, CurrentPhysicalPosition.Pos + str.Length); Task task = new Insert(); task.fromLine = nLine; task.fromPos = pos; task.length = str.Length; task.str = str; history.Add(task); if (MyTaskEvent != null) { TaskEventArgs args = new TaskEventArgs(); args.task = task; MyTaskEvent(this, args); } return task; }
/// <summary> /// 任意の位置に文字列を挿入 /// </summary> /// <param name="nLine">Line number. 0 origin</param> /// <param name="pos"></param> /// <param name="str"></param> public Task Insert(int nLine, int pos, string str) { //nLineがまだ存在しない行番号だった場合に備えて、その行までの存在しない行を全て作成 // 例えば、現在0-4行目が存在、8行目に文字を挿入する場合、 // 5-8行目を作成する。 for (int i = list.Count; i < nLine + 1; i++) { MyLine newLine = new MyLine(); list.Add(newLine); } MyLine line = list[nLine]; line.Insert(pos, str); CurrentPos = new Position(CurrentPos.Line, CurrentPos.Pos + str.Length); Task task = new Insert(); task.fromLine = nLine; task.fromPos = pos; task.length = str.Length; task.str = str; history.Add(task); if (MyTaskEvent != null) { TaskEventArgs args = new TaskEventArgs(); args.task = task; MyTaskEvent(this, args); } return task; }