Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Fixes issue #4747 Single-line members should not be collapsible.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed May 8, 2018
1 parent 6bfbf9f commit 85734b0
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -81,15 +81,15 @@ async void DocumentContext_DocumentParsed (object sender, EventArgs e)
UpdateFoldings (Editor, blockStructure.Spans, caretLocation, token);
}

static void UpdateFoldings (TextEditor Editor, ImmutableArray<BlockSpan> spans, int caretOffset, CancellationToken token = default (CancellationToken))
static void UpdateFoldings (TextEditor editor, ImmutableArray<BlockSpan> spans, int caretOffset, CancellationToken token = default (CancellationToken))
{
try {
var foldSegments = new List<IFoldSegment> ();

foreach (var blockSpan in spans) {
if (token.IsCancellationRequested)
return;
if (!blockSpan.IsCollapsible)
if (!blockSpan.IsCollapsible || IsSingleLine (editor, blockSpan))
continue;
var type = FoldingType.Unknown;
switch (blockSpan.Type) {
Expand All @@ -108,7 +108,7 @@ static void UpdateFoldings (TextEditor Editor, ImmutableArray<BlockSpan> spans,
}
var start = blockSpan.TextSpan.Start;
var end = blockSpan.TextSpan.End;
var marker = Editor.CreateFoldSegment (start, end - start);
var marker = editor.CreateFoldSegment (start, end - start);
if (marker == null)
continue;
foldSegments.Add (marker);
Expand All @@ -119,12 +119,18 @@ static void UpdateFoldings (TextEditor Editor, ImmutableArray<BlockSpan> spans,
}
Application.Invoke ((o, args) => {
if (!token.IsCancellationRequested)
Editor.SetFoldings (foldSegments);
editor.SetFoldings (foldSegments);
});
} catch (OperationCanceledException) {
} catch (Exception ex) {
LoggingService.LogError ("Unhandled exception in ParseInformationUpdaterWorkerThread", ex);
}
}

static bool IsSingleLine (TextEditor editor, BlockSpan blockSpan)
{
var startLine = editor.GetLineByOffset (blockSpan.TextSpan.Start);
return blockSpan.TextSpan.End <= startLine.EndOffsetIncludingDelimiter;
}
}
}

0 comments on commit 85734b0

Please sign in to comment.