pharo icon indicating copy to clipboard operation
pharo copied to clipboard

[Feature Request] Multi-Cursor Support

Open Gabriel-Darbord opened this issue 10 months ago • 10 comments

Currently, the Pharo code editor lacks multi-cursor support, a feature available in most modern editors such as VSCode. This limitation makes it cumbersome to perform bulk edits, such as renaming multiple occurrences of a variable, inserting text at multiple locations, or modifying code structure across lines.

The goal is to implement multi-cursor editing in the Pharo code editor, allowing users to edit multiple locations simultaneously. Ideally, the implementation should match the functionality of VSCode, with the following features:

  1. Adding and Managing Cursors
  • Manually place multiple cursors (e.g., Cmd+Click to insert additional cursors).
  • Select next occurrence of a word (Cmd+D) to quickly add a cursor at the next instance of the selected text.
  • Select all occurrences (Cmd+Shift+L) to apply changes to every instance in the current scope.
  • Remove the last added cursor (Cmd+U) to revert accidental selections.
  1. Editing with Multiple Cursors
  • Type, delete, copy, and paste at all cursors simultaneously.
  • Navigate and move all cursors together.
  • Undo/redo all actions as a group while preserving multi-cursor state.
  • Multi-line insertion (e.g., Cmd+Alt+Arrow Up/Down to insert a new cursor on the next line).
  1. [Optional] Column Selection Mode (Block Selection)
  • Create a vertical selection of text (e.g., Alt+Drag or Cmd+Shift+Alt+Arrow).

Expected development cost

Implementing multi-cursor editing will require:

  • Enhancements to the text editor's input handling.
  • UI feedback for multiple cursors (e.g., blinking cursors, selection highlighting).
  • Adjustments to the editing model to support simultaneous changes.
  • Handling of undo/redo operations in multi-cursor mode.

Additional context

Here are references to how other editors handle multi-cursor support:

Gabriel-Darbord avatar Feb 06 '25 15:02 Gabriel-Darbord

Brick has some multi-cursor support. Using Command-click to add cursors would conflict with existing functionality. See: GToolkit issue #3937.

Rinzwind avatar Feb 11 '25 21:02 Rinzwind

Note: this issue is linked to a GSoC 2025 proposal, so let's try to keep it active for now (i.e., do not close it).

I didn't know about Brick, it would be interesting to see how it's done as a reference for Rubric (the current editor for Pharo).

The shortcuts from the OP are directly from VSCode to let readers try them out easily, they are not indicative of the shortcuts that would be used in Pharo.

Gabriel-Darbord avatar Feb 11 '25 21:02 Gabriel-Darbord

Interest in Contributing to Multi-Cursor Support in Pharo Editor

Hi Gabriel,

I came across the discussion on implementing multi-cursor support in the Pharo code editor, and I’m really interested in contributing to this feature. Since modern editors like VSCode provide this functionality, adding it to Pharo would greatly enhance the editing experience.

Before I begin, I wanted to check if:

Is anyone actively working on this feature, or is it open for contribution?

Would it be best to start with cursor management (Cmd+Click, Cmd+D, etc.) before implementing full multi-cursor editing?

Are there any guidelines, existing discussions, or relevant classes I should focus on to ensure my approach aligns with Pharo’s architecture?

I’d love to collaborate with the team and make incremental contributions. Let me know if this is something I can start working on, and if you have any suggestions on how to proceed.

Looking forward to your thoughts!

Best regards, Yeruva Shanmukha Manohara Reddy

manoharreddyshanmukha avatar Apr 01 '25 05:04 manoharreddyshanmukha

Hi @manoharreddyshanmukha, thanks for your interest :) This is open for contributions. Since this is not a trivial issue, it will not be done with a single PR, so everyone should feel free to propose something, even if it only covers a small part.

For now, this is still in the early stages, so we need an understanding of the existing system and a plan:

  • Take a look at Rubric, the current code editor, and how/where cursors are implemented.
  • Album, a WIP editor forked from Brick discussed above, has some multi-cursor support, how is it implemented?
  • Which keyboard shortcuts should we use in Pharo? The shortcuts provided in the OP are from VSCode, and are not compatible with existing Pharo shortcuts.

Documenting such findings in this issue would be helpful. I think a good place to start implementing something is to be able to place multiple cursors with ???+click and see them in the editor, even if they don't do anything.

Gabriel-Darbord avatar Apr 01 '25 13:04 Gabriel-Darbord

Thank you for the detailed explanation! I truly appreciate the guidance. I’ll begin by exploring Rubric and Album to understand how cursors and multi-cursor support are implemented. Additionally, I’ll review Pharo’s existing shortcuts to identify any potential conflicts. Documenting these findings in the issue sounds like a great starting point. Once we have a clearer understanding, we can determine the best approach for introducing multi-cursor placement.

Also, may I ask if you are the mentor for this project for GSoC 2025? It would be helpful to know whom to reach out to for further guidance. Looking forward to contributing and sharing my progress soon!

manoharreddyshanmukha avatar Apr 01 '25 15:04 manoharreddyshanmukha

Yes, I am mentoring this project with @PalumboN. You can find the mentors and their contact at the bottom of each project's page: https://gsoc.pharo.org/code-text-improvements

Google Summer of Code with Pharo Consortium

Gabriel-Darbord avatar Apr 01 '25 17:04 Gabriel-Darbord

No multi-cursor support in Rubric, which can limit productivity for users accustomed to modern editors.

Album has partial multi-cursor support, but it’s still not fully integrated or stable.

Challenges for new users:

No clear indication of multi-cursor functionality.

Lack of easy-to-access UI controls for enabling/disabling multi-cursor mode.

Inconsistent behavior between single and multi-cursor operations.

Potential confusion with Pharo’s existing text selection and navigation shortcuts.

Areas for improvement:

Standardizing cursor storage and rendering in the UI.

Adding visual indicators for multiple cursors.

Implementing basic text operations (typing, deleting, and selecting text) across multiple cursors.

Enhancing onboarding with documentation or in-editor tooltips for new users.

Ensuring compatibility with existing text editing functions in Pharo.

** Keyboard Shortcut Research**

-Pharo’s existing shortcuts need to be considered to avoid conflicts.

-Current cursor movement shortcuts in Pharo:

-Arrow Keys → Move the cursor.

-Shift + Arrow Keys → Select text.

-Cmd + Left/Right → Move to the beginning/end of the line.

-Potential multi-cursor shortcuts:

-Cmd + Click → Add a new cursor.

-Cmd + Shift + Click → Remove a cursor.

-Cmd + D → Select the next occurrence of the selected text (if feasible).

-Cmd + Shift + L → Select all occurrences of the selected text.

manoharreddyshanmukha avatar Apr 02 '25 03:04 manoharreddyshanmukha

+ 1 to the issue

jordanmontt avatar Apr 25 '25 13:04 jordanmontt

@jordanmontt @Gabriel-Darbord "Appreciate the feedback! I’m happy to see this resonates with what I’ve included in my proposal — especially around shortcut design, improving visual cues, and onboarding support for new users. Looking forward to building on it and making it even stronger if selected!"

manoharreddyshanmukha avatar Apr 25 '25 16:04 manoharreddyshanmukha

When we are going to get the final project list @Gabriel-Darbord , i am very eager to know

Thank You

manoharreddyshanmukha avatar May 08 '25 18:05 manoharreddyshanmukha