[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move needs an affinity (prepend/append ; left/right) #180

Open
Swatinem opened this issue Sep 20, 2020 · 1 comment
Open

move needs an affinity (prepend/append ; left/right) #180

Swatinem opened this issue Sep 20, 2020 · 1 comment

Comments

@Swatinem
Copy link

Consider the following example: (https://jsfiddle.net/0eojnd8f/1/)

let s;
s = new MagicString("ABABAB"); // "ABABAB"
s.move(2,3,1); // "AABBAB"
s.move(4,5,1); // "AAABBB"
s.move(3,4,2); // "ABAABB"
s.move(5,6,2); // "ABBAAB"
s = new MagicString("142536"); // "142536"
s.move(2,3,1); // "124536"
s.move(4,5,1); // "123456"
s.move(3,4,2); // "152346"
s.move(5,6,2); // "156234"

I want to group all the As and Bs together, by moving the 2nd/3rd occurence after the first one. However this does not really work as intended.

The other way around, when I move the 1st/2nd before the 3rd one, things work:

s = new MagicString("142536"); // "142536"
s.move(0,1,4); // "425136"
s.move(2,3,4); // "451236"
s.move(1,2,5); // "512346"
s.move(3,4,5); // "123456"

This is a bit weird and unintuitive :-(

@kzc
Copy link
Contributor
kzc commented Feb 15, 2021

@Swatinem It is indeed a shortcoming. A PR supporting movePrependLeft, movePrependRight, moveAppendLeft, moveAppendRight would be welcome.

I imagine these methods could be implemented by making a copy of the substring to be moved, then calling remove and then the corresponding prependLeft, prependRight, appendLeft or appendRight methods. The move method could then be deprecated or removed.

Edit: After thinking about it, I realized that the algorithm outlined above would not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants