Skip to content

PR: Add multiline split & merge functionality to the Editor#25913

Open
hprodh wants to merge 3 commits intospyder-ide:masterfrom
hprodh:multiline_split_merge
Open

PR: Add multiline split & merge functionality to the Editor#25913
hprodh wants to merge 3 commits intospyder-ide:masterfrom
hprodh:multiline_split_merge

Conversation

@hprodh
Copy link
Copy Markdown
Contributor

@hprodh hprodh commented Apr 2, 2026

Description of Changes

Added Multiline split and merge operations to editor.

(note : no unit tests written)

  • Added replace_selected_text and auto_select_text methods to CodeEditor in codeeditor.py, for conveniently auto selecting line or word under cursor and replacing selected text by preserving selection. -> transform_upper_case and ``transform_upper_case` benefit now from selection preservation.

  • Added transform_multiline method, that uses ast (imported now at top-level in codeeditor.py) to parse sequences (of list/tuple items or args/kwargs combinations) or assignments within single or multiple lines of code, to output the one-line (merge) or one-per-line (split) version.

  • Added multiline_split and multiline_merge functions, calling all of the introduced methods, and handling indentation, to transform selected code to multiline or one-line in the editor.

  • Added 2 keyboard shortcut entries in config/main.py, assigning Alt+Shift+M to 'multiline split' operation and Alt+M to 'multiline merge'.

Video demo is here (but some trailing newline handling error has been fixed before PR).

Issue(s) Resolved

Fixes #25908

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:
hprodh

Copy link
Copy Markdown
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @hprodh!

And sorry for the big number of suggestions, they are only meant to make your code easier to read. The functionality looks good to me, although I haven't tested it yet.

If you haven't worked with suggestions before, please read this to learn how to apply them all in a single commit.

Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py Outdated
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py Outdated
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py Outdated
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py Outdated
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Comment thread spyder/plugins/editor/widgets/codeeditor/codeeditor.py Outdated
@ccordoba12 ccordoba12 changed the title Multiline split & merge functions in editor PR: Add multiline split & merge functionality to the Editor Apr 7, 2026
@ccordoba12 ccordoba12 added this to the v6.2.0a1 milestone Apr 7, 2026
Coding style refinements accepted

Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
@hprodh
Copy link
Copy Markdown
Contributor Author

hprodh commented Apr 7, 2026

Thanks for your review @ccordoba12 .

I tried to read the page but I think it is a bit outdated... anyway I went to the PR page, under the tab "Files changed", there I could click on "add to batch" (or whatever), I've done it for all suggestions. I did not see a button "commit batch" at the end, but now I see a second commit in the PR thread containing the accepted changes, thus I think it is done (is it ?)...

And no problem for the number of suggestions, I admit my coding style is a bit 'dense' 😆

@ccordoba12
Copy link
Copy Markdown
Member

I went to the PR page, under the tab "Files changed", there I could click on "add to batch" (or whatever), I've done it for all suggestions. I did not see a button "commit batch" at the end, but now I see a second commit in the PR thread containing the accepted changes, thus I think it is done (is it ?)...

Yep, it is. Gladly you easily found how to apply all suggestions in one go.

And no problem for the number of suggestions, I admit my coding style is a bit 'dense' 😆

No problem, it was fine. But we just need to make it look similar to our coding style so it's easier to maintain in the future.


I have an additional suggestion for you: could you add an entry for these new actions in the Edit menu?

image

That way it'll be easier to find this functionality for new users. And you could do that below the toggle upper/lowercase ones.

@hprodh
Copy link
Copy Markdown
Contributor Author

hprodh commented Apr 10, 2026

@ccordoba12
Done. I did even set some icons ! And tested.
screenshot_gui_entries

I did not translate the functions for every locale (and I won't), but I tested switching spyder to another language, the GUI entries still appear and work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality to the Editor to split selected code into mulitple lines or merge into one

2 participants