Jasonlhy / VSCode-Hungry-Delete

To delete an entire block of whitespace or tab, and reduce the time programmers need to press backspace
https://marketplace.visualstudio.com/items?itemName=jasonlhy.hungry-delete
MIT License
45 stars 4 forks source link

keep one space? #5

Open nanxiaobei opened 6 years ago

nanxiaobei commented 6 years ago

Can it keep one space after last word of previous line after backspace? like WebStorm's default behavior.

Jasonlhy commented 6 years ago

I can just add a setting to implement this feature. However, I find out WebStorm implementation do not always keep one space after the last word of previous line.

Not keep one space example:

<script src="js/plugins.js"></script>
|<script src="js/main.js"></script>

after pressing backspace =>

<script src="js/plugins.js"></script>|<script src="js/main.js"></script>

Their implementation only keep one space after the last word of previous line if the cursor is located at specific type of text such as html attribute and html innerText

Keep one space example 1:

<link rel="stylesheet"
|href="css/main.css">

after pressing backspace =>

<link rel="stylesheet" |href="css/main.css">

Keep one space example 2:

<p>Hello
|world! This is HTML5 Boilerplate.</p>

after pressing backspace =>

<p>Hello |world! This is HTML5 Boilerplate.</p>

But it seems that there is no API can get the token type (scope) of text under the cursor position. Reference

Jasonlhy commented 6 years ago

I just added this feature in 1.5.0 but it doesn't consider the cursor position. You can try try.

nanxiaobei commented 6 years ago

@Jasonlhy Thanks~

olavim commented 6 years ago

Would it be possible to add an option for exceptions after which a space should be added/removed? So as an example if I had a configuration such as

"hungryDelete.keepOneSpace": true,
"hungryDelete.keepOneSpaceExceptions": [">", "{", "("]

then the behavior in your examples would be in line with WebStorm. This isn't the perfect solution, but would be a big improvement nonetheless.

Jasonlhy commented 6 years ago

@olavim Noted, may add this feature in the weekend