public TextPosition GetSegmentStart(SnippetContent.Segment segment) { int index = this.currentSnippetSegments .Select((ss, i) => Tuple.Create(ss, i)) .Where(t => t.Item1.Contains(segment)) .Select(t => t.Item2) .Concat(new int[] { -1 }) .First(); if (index == -1) { return(new TextPosition(-1, -1)); } else { int row = this.currentSnippetStart.row + index; int col = index == 0 ? this.currentSnippetStart.col : 0; foreach (var s in this.currentSnippetSegments[index]) { if (s == segment) { break; } else { col += GetSegmentText(s).Length; } } return(new TextPosition(row, col)); } }
public void FinishEditingSnippet() { if (this.editingSnippet) { SnippetContent.Segment stop = this.currentSnippetSegments .SelectMany(s => s) .Where(s => s.Type == SnippetContent.SegmentType.Stop) .FirstOrDefault(); TextPosition start = new TextPosition(0, 0); if (stop != null) { start = GetSegmentStart(stop); } MoveToNextEditableSegment(); this.editingSnippet = false; this.currentSnippetSegments = null; this.currentEditingSegment = null; this.currentEditableSegments = null; this.currentAffectedSegments = null; this.textEditorBox.Controller.LeaveLimitedMode(); if (stop != null) { this.textEditorBox.Controller.Move(start, false, false); } this.textEditorBox.RedrawContent(false, true); } }
private void MoveToNextEditableSegment() { string text = this.textEditorBox.TextProvider.GetString( this.textEditorBox.Controller.LimitedStart, this.textEditorBox.Controller.LimitedEnd); this.currentEditingSegment.Value = text; FinishEditCurrentSegment(); int index = this.currentEditableSegments.IndexOf(this.currentEditingSegment); this.currentEditingSegment = this.currentEditableSegments[(index + 1) % this.currentEditableSegments.Count]; FillCurrentAffectedSegments(); StartEditCurrentSegment(); }
public string GetSegmentText(SnippetContent.Segment segment) { if (segment == this.currentEditingSegment) { if (this.textEditorBox.Controller.LimitedMode) { string text = this.textEditorBox.TextProvider.GetString( this.textEditorBox.Controller.LimitedStart, this.textEditorBox.Controller.LimitedEnd); return(text); } else { return(segment.Value); } } else { return(segment.Value ?? ""); } }
public void InsertSnippet(SnippetContent snippet) { if (!this.editingSnippet && snippet != null) { this.editingSnippet = true; TextPosition caret = this.textEditorBox.SelectionCaret; TextLine <TextEditorBox.LineInfo> line = this.textEditorBox.TextProvider[caret.row]; string prefix = line.GetString(0, caret.col); if (!string.IsNullOrWhiteSpace(prefix)) { prefix = ""; } List <List <SnippetContent.Segment> > segments = snippet.Compile(prefix); this.editingSnippet = true; this.currentSnippetSegments = segments; this.currentEditableSegments = segments .SelectMany(s => s) .Where(s => s.Type == SnippetContent.SegmentType.Editable && s.AssociatedSegment == null) .ToList(); this.currentSnippetStart = caret; if (this.currentEditableSegments.Count == 0) { this.textEditorBox.Controller.Input(GetSnippetText(segments), false); FinishEditingSnippet(); } else { this.currentEditingSegment = this.currentEditableSegments[0]; FillCurrentAffectedSegments(); SynchronizeAffectedSegments(); this.textEditorBox.Controller.Input(GetSnippetText(segments), false); StartEditCurrentSegment(); } } }