Browse Source

Fixed SD2-458: Tab is always replaced with 4 spaces

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@551 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
abd9f2604d
  1. 17
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs
  2. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

17
src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs

@ -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));

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

@ -900,7 +900,9 @@ namespace ICSharpCode.TextEditor @@ -900,7 +900,9 @@ namespace ICSharpCode.TextEditor
for (int j = currentLine.Length; j < end; j++) {
drawingPos += WideSpaceWidth;
}
column += (int)(drawingPos / WideSpaceWidth);
// add one pixel in column calculation to account for floating point calculation errors
column += (int)((drawingPos + 1) / WideSpaceWidth);
/* OLD Code (does not work for fonts like Verdana)
for (int j = start; j < end; ++j) {
char ch;

Loading…
Cancel
Save