Esempio n. 1
0
        /// <summary>
        /// Gets the word at position. Line and column numbers start from 1.
        /// </summary>
        public static WordAtPosition GetWordAtPosition(this IReadonlyTextDocument document, int line, int column)
        {
            if (line <= 0 || column <= 0)
            {
                return(WordAtPosition.Invalid);
            }

            if (line > 0 && (line > document.LineCount))
            {
                return(WordAtPosition.Invalid);
            }

            string lineText = document.GetLineText(line);

            // Check the column exists on the line. Allow the column to
            // be just after the last text character.
            if (column - 1 > lineText.Length)
            {
                return(WordAtPosition.Invalid);
            }

            return(TextEditorWords.GetWordAtPosition(
                       column,
                       TextEditorWords.DefaultWordRegex,
                       lineText));
        }
Esempio n. 2
0
        // LCS()

        static void WriteHunks(Queue <DiffHunk> qh, IReadonlyTextDocument baseDocument, IReadonlyTextDocument changedDocument, StringBuilder sb)
        {
            DiffHunk item;
            int      remStart;
            int      insStart;
            int      distance = 0;

            do
            {
                item     = qh.Dequeue();
                remStart = System.Math.Max(1, item.RemoveStart - (distance != 0 ? distance : item.Context));
                insStart = System.Math.Max(1, item.InsertStart - (distance != 0 ? distance : item.Context));

                for (int i = System.Math.Min(remStart, insStart); i < item.RemoveStart; i++)
                {
                    sb.Append(" ").AppendLine(baseDocument.GetLineText(i, false));
                }
                for (int i = item.RemoveStart; i < item.RemoveStart + item.Removed; i++)
                {
                    sb.Append("-").AppendLine(baseDocument.GetLineText(i, false));
                }
                for (int i = item.InsertStart; i < item.InsertStart + item.Inserted; i++)
                {
                    sb.Append("+").AppendLine(changedDocument.GetLineText(i, false));
                }

                if (qh.Count != 0)
                {
                    distance = item.DistanceTo(qh.Peek());
                }
            } while (qh.Count != 0);

            int remEnd = System.Math.Min(baseDocument.LineCount, item.RemoveStart + item.Removed + item.Context);

            for (int i = item.RemoveStart + item.Removed; i < remEnd; i++)
            {
                sb.Append(" ").AppendLine(baseDocument.GetLineText(i, false));
            }
        }
Esempio n. 3
0
        // Snatched from DefaultFormattingStrategy
        private string GetIndent(IReadonlyTextDocument d, int lineNumber, int terminateIndex)
        {
            string lineText = d.GetLineText(lineNumber);

            if (terminateIndex > 0)
            {
                lineText = terminateIndex < lineText.Length ? lineText.Substring(0, terminateIndex) : lineText;
            }

            StringBuilder whitespaces = new StringBuilder();

            foreach (char ch in lineText)
            {
                if (!char.IsWhiteSpace(ch))
                {
                    break;
                }
                whitespaces.Append(ch);
            }

            return(whitespaces.ToString());
        }
		// Snatched from DefaultFormattingStrategy
		private string GetIndent (IReadonlyTextDocument d, int lineNumber, int terminateIndex)
		{
			string lineText = d.GetLineText (lineNumber);
			if(terminateIndex > 0)
				lineText = terminateIndex < lineText.Length ? lineText.Substring(0, terminateIndex) : lineText;
			
			StringBuilder whitespaces = new StringBuilder ();
			
			foreach (char ch in lineText) {
				if (!char.IsWhiteSpace (ch))
					break;
				whitespaces.Append (ch);
			}
			
			return whitespaces.ToString ();
		}