コード例 #1
0
        public int GetLogicalColumn(TextEditorData editor, int visualColumn)
        {
            int curVisualColumn = 1;
            int offset          = Offset;
            int max             = offset + Length;
            var textLength      = editor.Document.TextLength;
            int tabSize         = editor.Options != null ? editor.Options.TabSize : 4;

            for (int i = offset; i < max; i++)
            {
                if (i < textLength && editor.Document.GetCharAt(i) == '\t')
                {
                    curVisualColumn = TextViewMargin.GetNextTabstop(editor, curVisualColumn, tabSize);
                }
                else
                {
                    curVisualColumn++;
                }
                if (curVisualColumn > visualColumn)
                {
                    return(i - offset + 1);
                }
            }
            return(Length + (visualColumn - curVisualColumn) + 1);
        }
コード例 #2
0
        public int GetVisualColumn(TextEditorData editor, int logicalColumn)
        {
            int result = 1;
            int offset = Offset;

            if (editor.Options.IndentStyle == IndentStyle.Virtual && Length == 0 && logicalColumn > DocumentLocation.MinColumn)
            {
                foreach (char ch in editor.GetIndentationString(Offset))
                {
                    if (ch == '\t')
                    {
                        result += editor.Options.TabSize;
                        continue;
                    }
                    result++;
                }
                return(result);
            }
            for (int i = 0; i < logicalColumn - 1; i++)
            {
                if (i < Length && editor.Document.GetCharAt(offset + i) == '\t')
                {
                    result = TextViewMargin.GetNextTabstop(editor, result);
                }
                else
                {
                    result++;
                }
            }
            return(result);
        }
コード例 #3
0
		public static void InsertTab (TextEditorData data)
		{
			if (!data.CanEditSelection)
				return;
			if (data.IsMultiLineSelection && data.MainSelection.SelectionMode != SelectionMode.Block) {
				IndentSelection (data);
				return;
			}
			using (var undo = data.OpenUndoGroup ()) {
				string indentationString = "\t";
				bool convertTabToSpaces = data.Options.TabsToSpaces;
				
				if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs) {
					for (int i = 1; i < data.Caret.Column; i++) {
						if (data.Document.GetCharAt (data.Caret.Offset - i) != '\t') {
							convertTabToSpaces = true;
							break;
						}
					}
				}
					
				if (convertTabToSpaces) {
					DocumentLocation visualLocation = data.LogicalToVisualLocation (data.Caret.Location);
					int tabWidth = TextViewMargin.GetNextTabstop (data, visualLocation.Column) - visualLocation.Column;
					indentationString = new string (' ', tabWidth);
				}
				if (!(data.IsMultiLineSelection && data.MainSelection.SelectionMode == SelectionMode.Block) && data.IsSomethingSelected)
					data.DeleteSelectedText ();
				data.InsertAtCaret (indentationString);
			}
		}
コード例 #4
0
        public int Replace(int offset, int count, string value)
        {
            StringBuilder sb = new StringBuilder();

            if (value != null)
            {
                bool             convertTabs = Options.TabsToSpaces;
                DocumentLocation loc         = Document.OffsetToLocation(offset);
                for (int i = 0; i < value.Length; i++)
                {
                    char ch = value[i];
                    switch (ch)
                    {
                    case '\u00A0':                     // convert non breaking spaces to standard spaces.
                        sb.Append(' ');
                        break;

                    case '\t':
                        if (convertTabs)
                        {
                            int tabWidth = TextViewMargin.GetNextTabstop(this, loc.Column) - loc.Column;
                            sb.Append(new string (' ', tabWidth));
                            loc.Column += tabWidth;
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case '\r':
                        if (i + 1 < value.Length && value[i + 1] == '\n')
                        {
                            i++;
                        }
                        goto case '\n';

                    case '\n':
                        sb.Append(EolMarker);
                        loc.Line++;
                        loc.Column = 0;
                        break;

                    default:
                        sb.Append(ch);
                        loc.Column++;
                        break;
                    }
                }
            }

            ((IBuffer)document).Replace(offset, count, sb.ToString());
            return(sb.Length);
        }
コード例 #5
0
        public string FormatString(DocumentLocation loc, string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return("");
            }
            StringBuilder sb          = new StringBuilder();
            bool          convertTabs = Options.TabsToSpaces;

            for (int i = 0; i < str.Length; i++)
            {
                char ch = str [i];
                switch (ch)
                {
                case '\u00A0':                 // convert non breaking spaces to standard spaces.
                    sb.Append(' ');
                    break;

                case '\t':
                    if (convertTabs)
                    {
                        int tabWidth = TextViewMargin.GetNextTabstop(this, loc.Column) - loc.Column;
                        sb.Append(new string (' ', tabWidth));
                        loc.Column += tabWidth;
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case '\r':
                    if (i + 1 < str.Length && str [i + 1] == '\n')
                    {
                        i++;
                    }
                    goto case '\n';

                case '\n':
                    sb.Append(EolMarker);
                    loc.Line++;
                    loc.Column = 0;
                    break;

                default:
                    sb.Append(ch);
                    loc.Column++;
                    break;
                }
            }
            return(sb.ToString());
        }
コード例 #6
0
        public int GetVisualColumn(TextEditorData editor, int logicalColumn)
        {
            int result = 0;

            for (int i = 0; i < logicalColumn; i++)
            {
                if (i < EditableLength && editor.Document.GetCharAt(Offset + i) == '\t')
                {
                    result = TextViewMargin.GetNextTabstop(editor, result);
                }
                else
                {
                    result++;
                }
            }
            return(result);
        }
コード例 #7
0
        public static void InsertTab(TextEditorData data)
        {
            if (!data.CanEditSelection)
            {
                return;
            }

            if (data.IsMultiLineSelection)
            {
                IndentSelection(data);
                return;
            }
            data.Document.BeginAtomicUndo();
            if (data.IsSomethingSelected)
            {
                data.DeleteSelectedText();
            }
            string indentationString  = "\t";
            bool   convertTabToSpaces = data.Options.TabsToSpaces;

            if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs)
            {
                for (int i = 1; i < data.Caret.Column; i++)
                {
                    if (data.Document.GetCharAt(data.Caret.Offset - i) != '\t')
                    {
                        convertTabToSpaces = true;
                        break;
                    }
                }
            }

            if (convertTabToSpaces)
            {
                DocumentLocation visualLocation = data.Document.LogicalToVisualLocation(data, data.Caret.Location);
                int tabWidth = TextViewMargin.GetNextTabstop(data, visualLocation.Column) - visualLocation.Column;
                indentationString = new string (' ', tabWidth);
            }
            int length = data.Insert(data.Caret.Offset, indentationString);

            data.Caret.Column += length;
            data.Document.EndAtomicUndo();
        }
コード例 #8
0
        public int GetLogicalColumn(TextEditorData editor, int visualColumn)
        {
            int curVisualColumn = 0;

            for (int i = 0; i < EditableLength; i++)
            {
                int curOffset = Offset + i;
                if (curOffset < editor.Document.Length && editor.Document.GetCharAt(curOffset) == '\t')
                {
                    curVisualColumn = TextViewMargin.GetNextTabstop(editor, curVisualColumn);
                }
                else
                {
                    curVisualColumn++;
                }
                if (curVisualColumn > visualColumn)
                {
                    return(i);
                }
            }
            return(EditableLength + (visualColumn - curVisualColumn));
        }
コード例 #9
0
        public int GetLogicalColumn(TextEditorData editor, int visualColumn)
        {
            int curVisualColumn = 1;
            int offset          = Offset;
            int max             = offset + EditableLength;

            for (int i = offset; i < max; i++)
            {
                if (i < editor.Document.Length && editor.Document.GetCharAt(i) == '\t')
                {
                    curVisualColumn = TextViewMargin.GetNextTabstop(editor, curVisualColumn);
                }
                else
                {
                    curVisualColumn++;
                }
                if (curVisualColumn > visualColumn)
                {
                    return(i - offset + 1);
                }
            }
            return(EditableLength + (visualColumn - curVisualColumn) + 1);
        }