Beispiel #1
0
 public Shell(IAbstractEditor editor)
 {
     _editor = editor;
     _editor.TextChanged += HandleTextChanged;
     _text = new TextWithChanges(_editor);
     _selectedTreeStack = new CowList<ParseTree>();
     _chordBuffer = new Queue<Synpl.EditorAbstraction.Key>();
     _structureModeAction = "m";
     _inStructureMode = false;
 }
Beispiel #2
0
 // TODO: Add unit test.
 //
 // The unit tests for pretty printing and indenting should check the behaviour in
 // the presence of unparsed text changes.
 //
 // TODO: Pretty printing should preserve the position of the cursor (relative to the
 // inner most node.
 public ParseTree PrettyPrint(int maxColumn, IAbstractEditor editor)
 {
     int line, column;
     editor.OffsetToLineColumn(StartPosition, out line, out column);
     TextWithChanges prettyPrintTwc = ToTwcSliceAsPrettyPrint(column, maxColumn);
     _text.RemoveSliceWithChanges(StartPosition, EndPosition, true);
     Console.WriteLine("pp: {0}", prettyPrintTwc.TestRender());
     Console.WriteLine("tb: {0}", _text.TestRender());
     _text.InsertSliceWithChanges(StartPosition, prettyPrintTwc, true);
     Console.WriteLine("ta: {0}", _text.TestRender());
     Console.WriteLine("{0}", ToStringAsCode(true));
     int offset = prettyPrintTwc.GetActualLength() - (EndPosition - StartPosition);
     _endPosition += offset;
     ParseTree result = Reparse(true);
     Console.WriteLine(result.ToStringAsTree());
     return result;
 }
Beispiel #3
0
 // TODO: Add unit test.
 public virtual ParseTree Indent(int position, int maxColumn, IAbstractEditor editor)
 {
     int currentLine, currentColumn;
     editor.OffsetToLineColumn(position, out currentLine, out currentColumn);
     if (currentLine == 0)
     {
         return GetRoot();
     }
     Console.WriteLine("!!! Indenting:");
     Console.WriteLine("current: {0} {1} {2}", position, currentLine, currentColumn);
     int lineStartOffset = editor.LineColumnToOffset(currentLine, 0);
     int testLine, testColumn;
     editor.OffsetToLineColumn(lineStartOffset, out testLine, out testColumn);
     Console.WriteLine("line start:{0}", lineStartOffset);
     ParseTree lineStarter = GetFirstNodeAfter(lineStartOffset);
     if (lineStarter == null || lineStarter.Parent == null)
     {
         return GetRoot();
     }
     // FIXME: the maximum column should not be hardcoded.
     return lineStarter.Parent.PrettyPrint(maxColumn, editor);
 }
Beispiel #4
0
 public TextWithChanges(IAbstractEditor editor)
 {
     _changes = new CowList<TextChange>();
     _editor = editor;
     _text = _editor.GetText(0, _editor.Length);
 }