예제 #1
0
        public void ParseAndRun(IList<string> lines, int start, out Range size, out string result)
        {
            string command = null;
            Dictionary<string, string> commandArgs = new Dictionary<string, string>();
            int end = start;

            while(end+1 < lines.Count
                    && lines[end + 1].Contains(":")
                    && lines[end + 1].StartsWith(" "))
                end += 1;

            foreach(var line in lines.Skip(start).Take(1 + end - start)) {
                var arg = line.Split(new char[] { ':' }, 2);

                if(command == null)
                    command = arg[0].Trim();

                commandArgs[arg[0].Trim()] = arg[1].Trim();
            }

            result = Invoke(command, commandArgs);
            if(result != null && !result.EndsWith("\n"))
                result = result + '\n';

            size = new Range(start) {
                EndRow = end,
                EndColumn = lines[end].Length
            };
        }
예제 #2
0
파일: Pad.cs 프로젝트: faboo/Agent
        public string GetText(Range range, bool delete)
        {
            string text = "";

            range.Normalize();

            // if we're doing a linewise (-ish) get
            if(range.EndRow != range.StartRow || range.EndColumn == Lines[range.EndRow].Text.Length) {

                for(int row = range.StartRow; row <= range.EndRow && row < Lines.Count; /* see the end */) {
                    Line line = Lines[row];
                    int startColumn = row == range.StartRow ? range.StartColumn : 0;
                    int endColumn = row == range.EndRow ? range.EndColumn : line.Text.Length;
                    int length = endColumn - startColumn + 1;

                    if(length + startColumn > line.Text.Length)
                        length = line.Text.Length - startColumn;

                    text += line.Text.Substring(startColumn, length) + "\n";

                    // somehow this decision here is messed up and row doesn't advance right.
                    if(startColumn == 0 && endColumn >= line.Text.Length) {
                        if(delete)
                            Lines.RemoveAt(row);
                        range.EndRow -= 1;
                    }
                    else {
                        if(delete)
                            line.Text = line.Text.Remove(startColumn, length);
                        row += 1;
                    }
                }
            }
            // if we're doing a characterwise get
            else {
                Line line = Lines[range.StartRow];
                int length = range.EndColumn - range.StartColumn;

                if(length + range.StartColumn > line.Text.Length)
                    length = line.Text.Length - range.StartColumn;

                if(length > 0) {
                    text += line.Text.Substring(range.StartColumn, length);
                    if(delete)
                        line.Text = line.Text.Remove(range.StartColumn, length);
                }
            }

            OnCursorModified(null, new EventArgs());

            return text;
        }
예제 #3
0
파일: Change.cs 프로젝트: faboo/Agent
 public Remove(Range range)
 {
     this.range = range;
 }
예제 #4
0
파일: Movement.cs 프로젝트: faboo/Agent
        public static Range WordEnd(PadEditor editor)
        {
            int words = editor.Count ?? 1;
            Range range = new Range(editor.Pad.Cursor);

            range.EndColumn = range.StartColumn;

            for(; words > 0; words -= 1) {
                range.EndColumn += 1;

                // move to the first non-space
                while(range.EndColumn < editor.Pad.CurrentLine.Text.Length
                        && Char.IsWhiteSpace(editor.Pad.CurrentLine.Text[range.EndColumn]))
                    ++range.EndColumn;

                while(range.EndColumn < editor.Pad.CurrentLine.Text.Length
                        && !Char.IsWhiteSpace(
                            editor.Pad.CurrentLine.Text[range.EndColumn + 1]))
                    ++range.EndColumn;
            }

            return range;
        }
예제 #5
0
파일: Movement.cs 프로젝트: faboo/Agent
        public static Range WordBeginning(PadEditor editor)
        {
            int words = editor.Count ?? 1;
            Range range = new Range(editor.Pad.Cursor) {
                EndColumn = editor.Pad.Column
            };

            for( ; words > 0; words -= 1) {
                range.EndColumn -= 1;

                // move to the first non-space
                while(range.EndColumn > 0
                        && Char.IsWhiteSpace(editor.Pad.CurrentLine.Text[range.EndColumn]))
                    --range.EndColumn;

                while(range.EndColumn > 0
                        && !Char.IsWhiteSpace(
                            editor.Pad.CurrentLine.Text[range.EndColumn - 1]))
                    --range.EndColumn;
            }

            return range;
        }
예제 #6
0
파일: Cursor.cs 프로젝트: faboo/Agent
 public Cursor(Range range)
 {
     Row = range.EndRow;
     Column = range.EndColumn;
 }