|
|
|
@ -17,11 +17,22 @@ namespace ICSharpCode.TextEditor.Actions
@@ -17,11 +17,22 @@ namespace ICSharpCode.TextEditor.Actions
|
|
|
|
|
public class Tab : AbstractEditAction |
|
|
|
|
{ |
|
|
|
|
public static string GetIndentationString(IDocument document) |
|
|
|
|
{ |
|
|
|
|
return GetIndentationString(document, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string GetIndentationString(IDocument document, TextArea textArea) |
|
|
|
|
{ |
|
|
|
|
StringBuilder indent = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
if (document.TextEditorProperties.ConvertTabsToSpaces) { |
|
|
|
|
indent.Append(new String(' ', document.TextEditorProperties.TabIndent)); |
|
|
|
|
int tabIndent = document.TextEditorProperties.TabIndent; |
|
|
|
|
if (textArea != null) { |
|
|
|
|
int column = textArea.TextView.GetVisualColumn(textArea.Caret.Line, textArea.Caret.Column); |
|
|
|
|
indent.Append(new String(' ', tabIndent - column % tabIndent)); |
|
|
|
|
} else { |
|
|
|
|
indent.Append(new String(' ', tabIndent)); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
indent.Append('\t'); |
|
|
|
|
} |
|
|
|
@ -57,10 +68,10 @@ namespace ICSharpCode.TextEditor.Actions
@@ -57,10 +68,10 @@ namespace ICSharpCode.TextEditor.Actions
|
|
|
|
|
{ |
|
|
|
|
switch (textArea.Caret.CaretMode) { |
|
|
|
|
case CaretMode.InsertMode: |
|
|
|
|
textArea.InsertString(GetIndentationString(textArea.Document)); |
|
|
|
|
textArea.InsertString(GetIndentationString(textArea.Document, textArea)); |
|
|
|
|
break; |
|
|
|
|
case CaretMode.OverwriteMode: |
|
|
|
|
string indentStr = GetIndentationString(textArea.Document); |
|
|
|
|
string indentStr = GetIndentationString(textArea.Document, textArea); |
|
|
|
|
textArea.ReplaceChar(indentStr[0]); |
|
|
|
|
if (indentStr.Length > 1) { |
|
|
|
|
textArea.InsertString(indentStr.Substring(1)); |
|
|
|
|