refreshVersions icon indicating copy to clipboard operation
refreshVersions copied to clipboard

Misalignment of delimiter in VersionsCatalogUpdater

Open SimonMarquis opened this issue 3 years ago • 3 comments

🐛 Describe the bug

The current delimiter used by VersionsCatalogUpdater creates a misalignment on toml update lines.

⚠️ Current behavior

https://github.com/jmfayard/refreshVersions/blob/1dcf5a247b78ed7abdc981d48f59c68cd4191778/plugins/core/src/test/resources/toml-refreshversions/expected.libs.toml#L11-L14

✅ Expected behavior

short-notation = "some.plugin.id:1.4"
##                            ⬆ :1.5"
##                            ⬆ :1.6"
##                            ⬆ :1.7"

📱 Tech info

The following logic seems to be the issue:

https://github.com/jmfayard/refreshVersions/blob/1dcf5a247b78ed7abdc981d48f59c68cd4191778/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt#L86-L92

The "magic numbers" seem to correspond to extra spaces, and therefore should rather be

val repeatCount = indexOfCurrentVersion - it - when {
    canFitSpaceAfterAvailableSymbol -> 1
    else -> 0
}

and I think we should deduce this from the trailingSpace instead, otherwise we don't catch both cases of the if.

https://github.com/jmfayard/refreshVersions/blob/1dcf5a247b78ed7abdc981d48f59c68cd4191778/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt#L92

So I would rewrite it to:

trailingSpace = if (canFitSpaceAfterAvailableSymbol && versionPrefix.startsWith(' ').not()) " " else ""
val repeatCount = indexOfCurrentVersion - it - trailingSpace.length
leadingSpace = " ".repeat(repeatCount.coerceAtLeast(0))

❓ Side question

What was the rationale for choosing this character ? It seems to be interpreted as emoji (at least on my setup), and breaks mouse selection even more 🙈 Would you be open to replace it with a simpler unicode character that won't be parsed as emoji?

SimonMarquis avatar Sep 12 '22 20:09 SimonMarquis

Mouse selection is cool, but have you tried keyboard selection?

Just hold shift and press the up arrow on your keyboard.

The fact that both keys, and the available update symbol are all upwards arrows should make it easier to remember 😉

Anyway, I will look into the details from my computer later, thanks for the report.

LouisCAD avatar Sep 13 '22 02:09 LouisCAD

Yes, I use both, and keyboard navigation seemed broken as well on my end.

The fact that both keys, and the available update symbol are all upwards arrows should make it easier to remember 😉

I don't get what you mean 😕

SimonMarquis avatar Sep 13 '22 06:09 SimonMarquis

On my work env (macos), the character is not rendered as emoji, but still has a different size in monospace font:

image

And multi-cursor selection does not work either (mouse & keyboard).

SimonMarquis avatar Sep 13 '22 08:09 SimonMarquis

👋 Hi, can I help improve the situation in any way? This issue is currently labelled as https://github.com/jmfayard/refreshVersions/labels/ready-for-development.

Should we update the character from to and fix the computed trailingSpace value?

SimonMarquis avatar Oct 02 '22 13:10 SimonMarquis

It seems like it has been handled in https://github.com/Splitties/refreshVersions/commit/c75cab1c9a688017887d32b9d259fe7fd3646e35

SimonMarquis avatar Aug 17 '23 17:08 SimonMarquis

Is the behavior correct on your side now in version 0.60.0?

LouisCAD avatar Aug 18 '23 07:08 LouisCAD

The keyboard selection works, but the mouse selection does not in the IDE. I don't think we can make it work on both sides without having a character of length 1 (i.e. vs ).

SimonMarquis avatar Aug 18 '23 09:08 SimonMarquis

How is mouse selection "not working"?

LouisCAD avatar Aug 20 '23 19:08 LouisCAD

🙈 nevermind, I was testing a wrong assumption.

Mouse selection (click and drag) and keyboard selection (shift and arrows) works, and that's all that matters! ✅

SimonMarquis avatar Aug 21 '23 08:08 SimonMarquis

Alright, I'm glad this was fixed!

LouisCAD avatar Aug 21 '23 12:08 LouisCAD