Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 84c262d

Browse files
committed
Introduced new FormatLines() overload in IFormattingStrategy for more convenience.
1 parent fa88338 commit 84c262d

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ bool NeedEndregion(IDocument document)
262262
return regions > endregions;
263263
}
264264

265+
public override void FormatLines(ITextEditor textArea)
266+
{
267+
using (textArea.Document.OpenUndoGroup()) {
268+
// In any other case: Simply format selection or whole document
269+
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(SD.ProjectService.CurrentProject);
270+
int formattedTextOffset = 0;
271+
int formattedTextLength = textArea.Document.TextLength;
272+
if (textArea.SelectionLength != 0) {
273+
formattedTextOffset = textArea.SelectionStart;
274+
formattedTextLength = textArea.SelectionLength;
275+
}
276+
CSharpFormatterHelper.Format(textArea, formattedTextOffset, formattedTextLength, formattingOptions.OptionsContainer);
277+
}
278+
}
279+
265280
public override void FormatLine(ITextEditor textArea, char ch) // used for comment tag formater/inserter
266281
{
267282
using (textArea.Document.OpenUndoGroup()) {
@@ -425,18 +440,6 @@ void FormatLineInternal(ITextEditor textArea, int lineNr, int cursorOffset, char
425440
}
426441
}
427442
return;
428-
429-
case (char) 0:
430-
// In any other case: Simply format selection or whole document
431-
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(SD.ProjectService.CurrentProject);
432-
int formattedTextOffset = 0;
433-
int formattedTextLength = textArea.Document.TextLength;
434-
if (textArea.SelectionLength != 0) {
435-
formattedTextOffset = textArea.SelectionStart;
436-
formattedTextLength = textArea.SelectionLength;
437-
}
438-
CSharpFormatterHelper.Format(textArea, formattedTextOffset, formattedTextLength, formattingOptions.OptionsContainer);
439-
break;
440443
}
441444
}
442445

src/Main/Base/Project/Src/Editor/Commands/ReformatSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void Run()
3535
if (editor == null)
3636
return;
3737

38-
editor.Language.FormattingStrategy.FormatLine(editor, (char) 0);
38+
editor.Language.FormattingStrategy.FormatLines(editor);
3939
}
4040
}
4141
}

src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ namespace ICSharpCode.SharpDevelop.Editor
2828
/// </summary>
2929
public interface IFormattingStrategy
3030
{
31+
/// <summary>
32+
/// Formats content in current selection or whole open file, if nothing is selected.
33+
/// </summary>
34+
/// <param name="editor">Current text editor.</param>
35+
void FormatLines(ITextEditor editor);
36+
3137
/// <summary>
3238
/// This function formats a specific line after <code>charTyped</code> is pressed.
3339
/// </summary>
@@ -53,6 +59,10 @@ public class DefaultFormattingStrategy : IFormattingStrategy
5359
{
5460
internal static readonly DefaultFormattingStrategy DefaultInstance = new DefaultFormattingStrategy();
5561

62+
public virtual void FormatLines(ITextEditor textArea)
63+
{
64+
}
65+
5666
public virtual void FormatLine(ITextEditor editor, char charTyped)
5767
{
5868
}

0 commit comments

Comments
 (0)