| 1: | // CursorKeys.cs | |
| 2: | // Copyright (C) 2000 Mike Krueger | |
| 3: | // Copyright (C) 2000 Andrea Paatz | |
| 4: | // | |
| 5: | // This program is free software; you can redistribute it and/or modify | |
| 6: | // it under the terms of the GNU General Public License as published by | |
| 7: | // the Free Software Foundation; either version 2 of the License, or | |
| 8: | // (at your option) any later version. | |
| 9: | // | |
| 10: | // This program is distributed in the hope that it will be useful, | |
| 11: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13: | // GNU General Public License for more details. | |
| 14: | // | |
| 15: | // You should have received a copy of the GNU General Public License | |
| 16: | // along with this program; if not, write to the Free Software | |
| 17: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18: | ||
| 19: | using System.Drawing; | |
| 20: | using System.Windows.Forms; | |
| 21: | using System; | |
| 22: | ||
| 23: | using SharpDevelop.DefaultEditor.Text; | |
| 24: | ||
| 25: | namespace SharpDevelop.DefaultEditor.Actions { | |
| 26: | ||
| 27: | public class CaretLeft : AbstractEditAction | |
| 28: | { | |
| 29: | public override void Execute(IEditActionServices services) | |
| 30: | { | |
| 31: | int curLineNr = services.Document.GetLineNumberOfOffset(services.Document.Caret.Offset); | |
| 32: | int curLineOffset = services.Document.GetLineOffset(curLineNr); | |
| 33: | ||
| 34: | int relOffset = services.Document.Caret.Offset - curLineOffset; | |
| 35: | ||
| 36: | if (relOffset > 0) { | |
| 37: | --services.Document.Caret.Offset; | |
| 38: | } else if (curLineNr > 0) { | |
| 39: | LineSegment lineAbove = services.Document.GetLineSegment(curLineNr - 1); | |
| 40: | services.Document.Caret.Offset = lineAbove.Offset + lineAbove.Length; | |
| 41: | } | |
| 42: | services.Document.SetDesiredColumn(); | |
| 43: | } | |
| 44: | } | |
| 45: | ||
| 46: | ||
| 47: | public class CaretRight : AbstractEditAction | |
| 48: | { | |
| 49: | public override void Execute(IEditActionServices services) | |
| 50: | { | |
| 51: | int curLineNr = services.Document.GetLineNumberOfOffset(services.Document.Caret.Offset); | |
| 52: | int curLineOffset = services.Document.GetLineOffset(curLineNr); | |
| 53: | ||
| 54: | int relOffset = services.Document.Caret.Offset - curLineOffset; | |
| 55: | ||
| 56: | if (relOffset < services.Document.GetLineSegment(curLineNr).Length) { | |
| 57: | ++services.Document.Caret.Offset; | |
| 58: | } else if (curLineNr < services.Document.TotalNumberOfLines - 1) { | |
| 59: | services.Document.Caret.Offset = services.Document.GetLineOffset(curLineNr + 1); | |
| 60: | } | |
| 61: | ||
| 62: | services.Document.SetDesiredColumn(); | |
| 63: | } | |
| 64: | } | |
| 65: | ||
| 66: | ||
| 67: | public class CaretUp : AbstractEditAction | |
| 68: | { | |
| 69: | public override void Execute(IEditActionServices services) | |
| 70: | { | |
| 71: | int curLineNr = services.Document.GetLineNumberOfOffset(services.Document.Caret.Offset); | |
| 72: | ||
| 73: | if (curLineNr > 0) { | |
| 74: | LineSegment line = services.Document.GetLineSegment(curLineNr - 1); | |
| 75: | services.Document.SetCaretToDesiredColumn(line); | |
| 76: | } | |
| 77: | } | |
| 78: | } | |
| 79: | ||
| 80: | ||
| 81: | public class CaretDown : AbstractEditAction | |
| 82: | { | |
| 83: | public override void Execute(IEditActionServices services) | |
| 84: | { | |
| 85: | int curLineNr = services.Document.GetLineNumberOfOffset(services.Document.Caret.Offset); | |
| 86: | ||
| 87: | if (curLineNr + 1 < services.Document.TotalNumberOfLines) { | |
| 88: | LineSegment line = services.Document.GetLineSegment(curLineNr + 1); | |
| 89: | services.Document.SetCaretToDesiredColumn(line); | |
| 90: | } | |
| 91: | } | |
| 92: | } | |
| 93: | ||
| 94: | ||
| 95: | public class WordRight : CaretRight | |
| 96: | { | |
| 97: | public override void Execute(IEditActionServices services) | |
| 98: | { | |
| 99: | LineSegment line = services.Document.GetLineSegmentOfOffset(services.Document.Caret.Offset); | |
| 100: | if (services.Document.Caret.Offset == line.Offset + line.Length || line.Length == 0) { | |
| 101: | base.Execute(services); | |
| 102: | } else { | |
| 103: | int nextWordStart = TextUtilities.FindNextWordEnd(services.Document, services.Document.Caret.Offset); | |
| 104: | services.Document.Caret.Offset = nextWordStart; | |
| 105: | } | |
| 106: | services.Document.SetDesiredColumn(); | |
| 107: | } | |
| 108: | } | |
| 109: | ||
| 110: | ||
| 111: | public class WordLeft : CaretLeft | |
| 112: | { | |
| 113: | public override void Execute(IEditActionServices services) | |
| 114: | { | |
| 115: | LineSegment line = services.Document.GetLineSegmentOfOffset(services.Document.Caret.Offset); | |
| 116: | if (services.Document.Caret.Offset == line.Offset || line.Length == 0) { | |
| 117: | base.Execute(services); | |
| 118: | } else { | |
| 119: | int prevWordStart = TextUtilities.FindPrevWordStart(services.Document, services.Document.Caret.Offset); | |
| 120: | services.Document.Caret.Offset = prevWordStart; | |
| 121: | } | |
| 122: | services.Document.SetDesiredColumn(); | |
| 123: | } | |
| 124: | } | |
| 125: | ||
| 126: | ||
| 127: | public class ScrollLineUp : AbstractEditAction | |
| 128: | { | |
| 129: | public override void Execute(IEditActionServices services) | |
| 130: | { | |
| 131: | services.AutoClearSelection = false; | |
| 132: | services.FirstVisibleLine = Math.Max(0, services.FirstVisibleLine - 1); | |
| 133: | } | |
| 134: | } | |
| 135: | ||
| 136: | ||
| 137: | public class ScrollLineDown : AbstractEditAction | |
| 138: | { | |
| 139: | public override void Execute(IEditActionServices services) | |
| 140: | { | |
| 141: | services.AutoClearSelection = false; | |
| 142: | services.FirstVisibleLine = Math.Max(0, Math.Min(services.Document.TotalNumberOfLines - 3, services.FirstVisibleLine + 1)); | |
| 143: | } | |
| 144: | } | |
| 145: | } |
This page was automatically generated by SharpDevelop.