Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/PowerShellRun/Application/InternalEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ internal class InternalEntry
public BackgroundRunspace.Task? PreviewTask { get; set; } = null;
private int _previewTaskExecutionCount = 0;
private string[]? _previewLines = null;
private readonly object? _previewLinesLock = null;
private readonly object? _previewTaskLock = null;
private bool _previewLinesUpdatedByTask = false;
private TextBox.WrappedText? _previewWrappedTextCache = null;
private int _previewWrappedTextCacheWidth = 0;

public InternalEntry(SelectorEntry selectorEntry)
{
Expand Down Expand Up @@ -71,7 +73,7 @@ public InternalEntry(SelectorEntry selectorEntry)

if (selectorEntry.PreviewAsyncScript is not null)
{
_previewLinesLock = new object();
_previewTaskLock = new object();
}
}

Expand All @@ -89,10 +91,10 @@ public ActionKey[] GetActionKeysMultiSelection()

public void CompletePreviewTask(System.Collections.ObjectModel.Collection<PSObject> taskResult)
{
if (_previewLinesLock is null)
if (_previewTaskLock is null)
return;

lock (_previewLinesLock)
lock (_previewTaskLock)
{
if (taskResult.Count > 0 && taskResult[0] is not null)
{
Expand All @@ -106,22 +108,39 @@ public void CompletePreviewTask(System.Collections.ObjectModel.Collection<PSObje

public string[]? GetPreviewLines()
{
if (_previewLinesLock is null)
if (_previewTaskLock is null)
return _previewLines;

lock (_previewLinesLock)
lock (_previewTaskLock)
{
return _previewLines;
}
}

public TextBox.WrappedText? GetPreviewWrappedText(int maxWidth)
{
var previewLines = GetPreviewLines();
if (previewLines == null)
return null;

if (_previewWrappedTextCache is not null && _previewWrappedTextCacheWidth == maxWidth)
{
return _previewWrappedTextCache;
}

_previewWrappedTextCache = new TextBox.WrappedText(previewLines, maxWidth);
_previewWrappedTextCacheWidth = maxWidth;

return _previewWrappedTextCache;
}

public void UpdatePreviewTask()
{
IsUpdated = false;
if (_previewLinesLock is null)
if (_previewTaskLock is null)
return;

lock (_previewLinesLock)
lock (_previewTaskLock)
{
if (PreviewTask is null && _previewTaskExecutionCount == 0)
{
Expand Down
19 changes: 17 additions & 2 deletions src/PowerShellRun/Application/ResultWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,28 @@ private void BuildUi()
{
if (theme.PreviewEnable)
{
var previewLines = internalEntry.GetPreviewLines();
string[]? previewLines = null;
int previewInitialVerticalScroll = 0;
if (theme.PreviewTextWrapMode != TextWrapMode.None)
{
var wrappedPreview = internalEntry.GetPreviewWrappedText(_previewBox.GetInnerLayout().Width);
if (wrappedPreview is not null)
{
previewLines = wrappedPreview.Lines;
previewInitialVerticalScroll = wrappedPreview.GetStartLineIndex(selectorEntry.PreviewInitialVerticalScroll);
}
}
else
{
previewLines = internalEntry.GetPreviewLines();
previewInitialVerticalScroll = selectorEntry.PreviewInitialVerticalScroll;
}
int previewLineCount = (previewLines is not null) ? previewLines.Length : 0;

if (IsFocusedEntryUpdated() || _isFocusedEntryContentUpdated)
{
_previewBox.ClearAndSetVerticalScroll(
selectorEntry.PreviewInitialVerticalScroll,
previewInitialVerticalScroll,
previewLineCount);
}
else
Expand Down
1 change: 1 addition & 0 deletions src/PowerShellRun/Application/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class Theme
public FontColor? EntryScrollBarBackgroundColor { get; set; } = null;

public bool PreviewEnable { get; set; } = true;
public TextWrapMode PreviewTextWrapMode { get; set; } = TextWrapMode.None;
public FontColor? PreviewForegroundColor { get; set; } = null;
public FontColor? PreviewBackgroundColor { get; set; } = null;
public FontStyle PreviewStyle { get; set; } = FontStyle.Default;
Expand Down
4 changes: 4 additions & 0 deletions src/PowerShellRun/UI/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public void Write()
shouldSetEscapeSequence = true;
}

// Low priority escape sequence is applied here before color and style settings.
// e.g. Escape sequences for highlighted characters. The highlight color setting is stronger.
if (escapeSequence is not null && shouldSetEscapeSequence && escapeSequenceLowPriority)
{
builder.Append(escapeSequence);
Expand Down Expand Up @@ -337,6 +339,8 @@ public void Write()
builder.Append(FontStyleTable.GetEscapeCode(cell.FontStyle));
}

// Normal priority escape sequence is applied here after color and style settings.
// It is higher priority than color and style settings.
if (escapeSequence is not null && shouldSetEscapeSequence && !escapeSequenceLowPriority)
{
builder.Append(escapeSequence);
Expand Down
Loading