Skip to content

Whitespace only lines have no effects on trimming #254

@WEGFan

Description

@WEGFan

Describe the bug
When using these actions, lines containing only whitespaces will leave unchanged: Trim, Trim Trailing, Trim Leading, Replace Whitespaces with a Single Space Char, Remove All Spaces

To Reproduce
Steps to reproduce the behavior:

  1. Create a new text file containing:

        <- 4 spaces
    4 spaces ->    
        <- 4 spaces ->    
    v 4 spaces line v
        
    ^ 4 spaces line ^
    

    The dots are spaces:

    Image

  2. Select all text, and use "Trim Trailing"

  3. The text becomes

        <- 4 spaces
    4 spaces ->
        <- 4 spaces ->
    v 4 spaces line v
        
    ^ 4 spaces line ^
    

    Image

Expected behavior
Line 5 should be empty, the result text should be:

    <- 4 spaces
4 spaces ->
    <- 4 spaces ->
v 4 spaces line v

^ 4 spaces line ^

Image

Environment

IntelliJ IDEA 2024.3.4 (Ultimate Edition)
Build #IU-243.25659.39, built on February 27, 2025
Licensed to Fan WEG
Subscription is active until August 13, 2025.
Runtime version: 21.0.6+8-b631.39 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 10.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 3000M
Cores: 4
Registry:
  ide.tooltip.initialDelay=313
  ide.hide.cursor.when.typing=false
  debugger.mayBringFrameToFrontOnBreakpoint=false
  vcs.log.linear.bek.sort=true
  caches.scanningThreadsCount=2
  projectView.choose.directory.on.compacted.middle.packages=true
  projectView.always.show.inner.classes=true
  parameter.info.editor.font=true
  show.diff.preview.as.editor.tab.with.single.click=true
  ide.find.show.replacement.hint.for.simple.regexp=true
  batch.inspections.number.of.threads=2
  editor.codeVision.more.inlay=true
  jvm.dfa.analysis.ui.security.analysis.window.was.shown=true
Non-Bundled Plugins:
  com.intellij.classic.ui (243.21565.122)
  net.codestats.plugin.atom.intellij (1.0.9)
  de.netnexus.camelcaseplugin (3.0.12)
  jclasslib (6.0.5.1)
  com.haulmont.jpab (243.24978.46)
  com.intellij.spring.debugger (243.22562.13)
  Statistic (4.4)
  String Manipulation (9.15.0)
  com.intellij.spring.websocket (243.21565.129)
  de.santiv.fastscrolling (1.2)
  com.intellij.plugins.vscodekeymap (243.21565.122)
  net.seesharpsoft.intellij.plugins.csv (4.0.2)
  org.exbin.deltahex.intellij (0.2.11.1)
  com.bruce.easycode.mybatiscodehelper (2025.1.2)
  JRebelPlugin (2025.2.0)
  izhangzhihao.rainbow.brackets (2024.2.10-241)
  org.mapstruct.intellij (1.8.0)
  com.alibabacloud.intellij.cosy (2.3.0)
  com.nasller.CodeGlancePro (1.9.7)
  io.github.linwancen.show-comment (2.23.0.2025.04.20_22.41)
  org.sonarlint.idea (10.21.0.81149)
  zielu.gittoolbox (600.1.2+243)
  mobi.hsz.idea.gitignore (4.5.6)
  com.ccnode.codegenerator.MyBatisCodeHelperProMarketPlace (3.4.1+2321)
Kotlin: 243.25659.39-IJ

Additional context
I think the StringUtils.isBlank check causes the issue

for (int i = 0; i < textParts.length; i++) {
if (!StringUtils.isBlank(textParts[i])) {
textParts[i] = transformByLine(actionContext, textParts[i]);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions