Exemplo n.º 1
0
 void ReplaceSingleLineText(TextArea textArea, SelectionSegment lineSegment, string newText, out int insertionLength)
 {
     if (lineSegment.Length == 0)
     {
         if (newText.Length > 0 && textArea.ReadOnlySectionProvider.CanInsert(lineSegment.StartOffset))
         {
             newText = AddSpacesIfRequired(newText, new TextViewPosition(document.GetLocation(lineSegment.StartOffset), lineSegment.StartVisualColumn));
             textArea.Document.Insert(lineSegment.StartOffset, newText);
         }
     }
     else
     {
         ISegment[] segmentsToDelete = textArea.GetDeletableSegments(lineSegment);
         for (int i = segmentsToDelete.Length - 1; i >= 0; i--)
         {
             if (i == segmentsToDelete.Length - 1)
             {
                 if (segmentsToDelete[i].Offset == SurroundingSegment.Offset && segmentsToDelete[i].Length == SurroundingSegment.Length)
                 {
                     newText = AddSpacesIfRequired(newText, new TextViewPosition(document.GetLocation(lineSegment.StartOffset), lineSegment.StartVisualColumn));
                 }
                 textArea.Document.Replace(segmentsToDelete[i], newText);
             }
             else
             {
                 textArea.Document.Remove(segmentsToDelete[i]);
             }
         }
     }
     insertionLength = newText.Length;
 }
Exemplo n.º 2
0
 public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     if (m_jsonEditorViewModel.IsBetweenQoats)
       {
     int offset = m_jsonEditorViewModel.Caret.Offset;
     List<char> startChars = new List<char> {m_autoCompleteValue.SchemaObject.AutoCompletePathSeperator, '"'};
     if (m_autoCompleteValue.SchemaObject.Prefix.Length > 0)
       startChars.Add(m_autoCompleteValue.SchemaObject.Prefix.Last());
     int indexQuotStart = m_jsonEditorViewModel.TextDocument.Text.LastIndexOfAny(startChars.ToArray(), offset - 1, offset - 1) + 1;
     int indexQuatEnd = m_jsonEditorViewModel.TextDocument.Text.IndexOf('"', offset);
     int indexLineBreak = m_jsonEditorViewModel.TextDocument.Text.IndexOf('\n', offset);
     if (indexQuatEnd >= indexQuotStart && indexQuatEnd < indexLineBreak)
       completionSegment = new SelectionSegment(indexQuotStart, indexQuatEnd);
       }
       int endOffset = completionSegment.Offset + Text.Length;
       textArea.Document.Replace(completionSegment, (Text + m_autoCompleteValue.SchemaObject.Suffix).Replace("\\", "\\\\"));
       m_jsonEditorViewModel.Caret.Offset = endOffset;
       string value = m_autoCompleteValue.SchemaObject.RemovePrefixAndSuffix(m_jsonEditorViewModel.GetCurrentValue());
       if (Text.StartsWith(".." + m_autoCompleteValue.SchemaObject.AutoCompletePathSeperator) && value.Any(char.IsLetterOrDigit))
       {
     value = value.Substring(0, value.Length - 4);
     int startIndex = value.LastIndexOf(m_autoCompleteValue.SchemaObject.AutoCompletePathSeperator);
     if (startIndex == -1)
       startIndex = m_autoCompleteValue.SchemaObject.Prefix.Length;
     else
     {
       startIndex++;
     }
     m_jsonEditorViewModel.TextDocument.Replace(
       m_jsonEditorViewModel.Caret.Offset - 4 - (value.Length - startIndex), (value.Length - startIndex) + 4, "");
       }
       m_jsonEditorViewModel.UpdateAutoCompletList = true;
 }
Exemplo n.º 3
0
        TextViewPosition GetEnd()
        {
            SelectionSegment segment = (startLine < endLine ? segments.Last() : segments.First());

            if (startXPos < endXPos)
            {
                return(new TextViewPosition(document.GetLocation(segment.EndOffset), segment.EndVisualColumn));
            }
            else
            {
                return(new TextViewPosition(document.GetLocation(segment.StartOffset), segment.StartVisualColumn));
            }
        }
 private void ReplaceSingleLineText(TextArea textArea, SelectionSegment lineSegment, string newText, out int insertionLength)
 {
     if (lineSegment.Length == 0)
     {
         if (newText.Length > 0 && textArea.ReadOnlySectionProvider.CanInsert(lineSegment.StartOffset))
         {
             newText = AddSpacesIfRequired(newText, new TextViewPosition(document.GetLocation(lineSegment.StartOffset), lineSegment.StartVisualColumn), new TextViewPosition(document.GetLocation(lineSegment.EndOffset), lineSegment.EndVisualColumn));
             textArea.Document.Insert(lineSegment.StartOffset, newText);
         }
     }
     else
     {
         ISegment[] segmentsToDelete = textArea.GetDeletableSegments(lineSegment);
         for (int i = segmentsToDelete.Length - 1; i >= 0; i--)
         {
             if (i == segmentsToDelete.Length - 1)
             {
                 if (segmentsToDelete[i].Offset == SurroundingSegment.Offset && segmentsToDelete[i].Length == SurroundingSegment.Length)
                 {
                     newText = AddSpacesIfRequired(newText, new TextViewPosition(document.GetLocation(lineSegment.StartOffset), lineSegment.StartVisualColumn), new TextViewPosition(document.GetLocation(lineSegment.EndOffset), lineSegment.EndVisualColumn));
                 }
                 textArea.Document.Replace(segmentsToDelete[i], newText);
             }
             else
             {
                 textArea.Document.Remove(segmentsToDelete[i]);
             }
         }
     }
     insertionLength = newText.Length;
 }