cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.1k stars 77 forks source link

Improve "chuck trailing line" cleanup #738

Open pokey opened 2 years ago

pokey commented 2 years ago

Should leave exactly one space if the next line has content. Eg

    hello world
    whatever

Today, "chuck trailing line" on the first line leaves you with

    hello world    whatever

But we'd prefer

    hello world whatever

If the next line is empty, it just deletes it

Could implement this by having getTrailingDelimiterTarget for line return a target that creates a custom removal edit

AndreasArvidsson commented 2 years ago
  1. What about if the next line has no indentation should our remove command actually add white space?
  2. What about if you have a line with indentation and say chuck leading? should we then remove the leading white spaces and thereby mess up the indentation?
  3. How do we handle highlights in all of the above scenarios?
pokey commented 2 years ago

As usual, great questions 😄

  1. What about if the next line has no indentation should our remove command actually add white space?

Yes, it should replace all whitespace (including newlines, indentation, etc) from from end of line to start of content on next line with a single space character

  1. What about if you have a line with indentation and say chuck leading? should we then remove the leading white spaces and thereby mess up the indentation?

Why would it mess up indentation? I'd argue for the following:

If you have:

    hello world
    whatever

Saying, "chuck leading line" on the second line should leave you with

    hello world whatever

Ie it replaces all leading indentation and newline with a single space

However, if the preceding line is empty, it should not touch indentation on targeted line

  1. How do we handle highlights in all of the above scenarios?

I think if next / prev line is empty, hit it with full line highlight. Otherwise highlight newline and indentation that was removed with red before replacing it with space