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 21 years ago
parent
commit
abd9f2604d
  1. 27
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs
  2. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

27
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));
@ -131,7 +142,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -131,7 +142,7 @@ namespace ICSharpCode.TextEditor.Actions
/// else
/// there were no leading tabs or spaces on this line so do nothing
/// MS Visual Studio 6 strategy:
****/
****/
// string temp = document.GetText(line.Offset,line.Length);
if (line.Length > 0) {
int charactersToRemove = 0;
@ -222,7 +233,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -222,7 +233,7 @@ namespace ICSharpCode.TextEditor.Actions
if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("LineComment")) {
new ToggleLineComment().Execute(textArea);
} else if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentBegin") &&
textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentBegin")) {
textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentBegin")) {
new ToggleBlockComment().Execute(textArea);
}
}
@ -778,7 +789,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -778,7 +789,7 @@ namespace ICSharpCode.TextEditor.Actions
}
// now delete from the caret to the beginning of the word
LineSegment line =
textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
// if we are not at the beginning of a line
if(textArea.Caret.Offset > line.Offset) {
int prevWordStart = TextUtilities.FindPrevWordStart(textArea.Document,
@ -793,7 +804,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -793,7 +804,7 @@ namespace ICSharpCode.TextEditor.Actions
if(textArea.Caret.Offset == line.Offset) {
// if we are not on the first line
int curLineNr =
textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
if(curLineNr > 0) {
// move to the end of the line above
LineSegment lineAbove = textArea.Document.GetLineSegment(curLineNr -
@ -834,7 +845,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -834,7 +845,7 @@ namespace ICSharpCode.TextEditor.Actions
}
// now delete from the caret to the beginning of the word
LineSegment line =
textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
if(textArea.Caret.Offset == line.Offset + line.Length) {
// if we are at the end of a line
base.Execute(textArea);

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