Skip to content

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

@hprodh

Description

@hprodh

Hello Spyder maintainers,

I have been wishing for this feature that can turn sequences or call args, list or tuple items, dictionaries key-value pairs, and multiple assignment to their 'one per line' (transform_to_multiline) or 'all in one line' (transform_to_oneline) versions.

I actually implemented it, and it works neatly !

I might produce a PR (or maybe first a video demo).


For now I have several questions, on a technical aspect :

What will be the easiest way to make a PR ? Is it by forking the repo, then clone on local, then commit changes, push, then submit the PR via github ?? (I am only used to git in a mono-user usage, and not much experienced with branches, but I can follow a procedure.)

A bit more technical :
I guess the main concern about the changes is that I import (lazily) ast into codeeditor.py... Is this acceptable and could ast be imported at top-level ? (only one function uses ast to identify top-level items of sequences/assignments, the function might also belong to another file)

Even more technical (on code architecture) (maybe that question belongs to the PR):
There are several functions within the BaseEditMixin in mixins.py (namely insert_text, replace_text, remove_text), that seem to be made to be used for this kind of feature modifying the editor contents, but that also emit some signals, trying to use them yielded some instability/cursor glitches. I ended up working from the transform_to_uppercase (and lowercase) functions as a basis. I added a replace_selected_text method, should it belong to codeeditor.py or somewhere else ? (Note : transform_to_uppercase (and lowercase) are slightly improved by the changes as the cursor selection zone is now preserved upon transformation of the text)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions