Console icon indicating copy to clipboard operation
Console copied to clipboard

Show-ListView trims leading spaces

Open lundebro opened this issue 4 years ago • 1 comments

Hi, We're using SPE a lot for validating various content, and we have noticed that Show-ListView seems to trim the values in the cells, which makes it difficult to highlight content that has leading whitespace. By comparison, Format-Table seems to keep the whitespace. See the example below. We have experimented with replacing whitespace with   which works well enough in the listview control itself, but it doesn't look very nice in the Excel export. It would be nice if there was a way to prevent the data from being trimmed before being displayed in the listview.

Expected Behavior

Values in Show-ListView cells should include leading whitespace

Actual Behavior

Values in Show-ListView trims leading whitespace

Steps to Reproduce the Problem

$data = [PSCustomObject]@()
$data += [PSCustomObject]@{
  Value = " test"
  Status = "leading whitespace"
}
$data += [PSCustomObject]@{
  Value = "test"
  Status = "valid"
}
$data | Format-Table
$data | Show-ListView
  • [x] Tested issue with clean install of Sitecore and the latest available version of SPE.

  • [ ] Asked questions on the Sitecore Slack Chat channel.

  • [x] Reviewed questions and answers on the Sitecore Stack Exchange.

lundebro avatar Jan 25 '22 11:01 lundebro

Having a look at the generated HTML the space is still there. The issue is that the browser doesn't render the leading space. Perhaps the least problematic option is to add a column saying there is an issue.

function Test-Spacing {
    param(
        [string]$Text
    )
    
    $text -eq $text.Trim()
}

$data = [PSCustomObject]@()
$data += [PSCustomObject]@{
  Value = " test"
  Status = "leading whitespace"
  IsValid = (Test-Spacing -Text " test")
}
$data += [PSCustomObject]@{
  Value = "test"
  Status = "valid"
  IsValid = (Test-Spacing -Text "test")
}

$data | Show-ListView

image

michaellwest avatar Apr 30 '22 14:04 michaellwest

There is nothing we can fix here. For highlighting items by indenting, they can be converted the leading spaces to &bnsp; before feeding them to Show-ListView.

AdamNaj avatar May 09 '24 22:05 AdamNaj