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

[WIP] PR: Add multiline editing capability in the Editor #4987

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jnsebgosselin
Copy link
Member

@jnsebgosselin jnsebgosselin commented Aug 17, 2017

Tasks

  • Any new code on this PR should be Python 3 only
  • Create helpers on the extension manager for common tasks (alt, ctrl, keys)
  • Simplify the key_press handler to use helper methods (copy, paster and other actions)
  • Provide a way to query for the current shortcuts sequences used for common actions
  • Check usage of Mac pressed keys. On mac leaving a key pressed for a while sometimes produces extra options (@steff456, @juanis2112)
  • Check Alt+Gr behavior on windows since this is source of weirdness (@dalthviz)
  • Check LSP calls are working as expected after a extension has accepted an event.
    • If this is not the case try to extend the Extension base class to do this handling. Extensions should not need to care about LSP issues in general, unless the extension is doing something with LSP results. In that case we will also need to expose LSP signals so that the extension editors can connect to them.
  • Update documentation inside the extension editor to explain usage. The event.accept, ignore way of handling signals and events as well as the purpose of these signals.
  • Check color of Cursor is correctly querying the editor color theme.
  • Check the cursors are blinking in sync (this was one of the issues we had in the past.
  • Check performance of editor if many cursors are added.
  • Check how cursor history is affected by multiple cursors (cursor history should probably be disabled if multi line editing @ccordoba12 ?)
  • We need test for all the corner cases :-)

Pull Request Checklist

  • Read and followed this repo's Contributing Guidelines
  • Based your PR on the latest version of the correct branch (master or 3.x)
  • Followed PEP8 for code style
  • Ensured your pull request hasn't eliminated unrelated blank lines/spaces,
    modified the spyder/defaults directory, or added new icons/assets
  • Wrote at least one-line docstrings for any new functions
  • Added at least one unit test covering the changes, if at all possible
  • Described your changes and the motivation for them below
  • Noted what issue(s) this pull request resolves, creating one if needed
  • Included a screenshot, if this PR makes any visible changes to the UI

Description of Changes

The idea is to be able to set multiple cursors to edit at different places of the code at the same time like it is done in Sublime for example.

This feature is not supported by the Qt framework, so we need to go around it and re-implement a lot of low level stuff.

mulitline_spyder

Issue(s) Resolved

Fixes #2112
Depends on PR #5002

@pep8speaks
Copy link

pep8speaks commented Aug 17, 2017

Hello @jnsebgosselin! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-29 00:56:30 UTC

@ccordoba12 ccordoba12 added this to the v4.0beta2 milestone Aug 17, 2017
@ccordoba12
Copy link
Member

Thanks a lot @jnsebgosselin! This is looking great!

@rlaverde, please review this one and give @jnsebgosselin feedback about his implementation.

@goanpeca
Copy link
Member

@jnsebgosselin great work :-)

Question, why did we need to create a new class on top of the base editor?

Also, cursors should occupy a bit less than the full height of text so when pile together, they do not look like a single super long line

@rlaverde
Copy link
Member

rlaverde commented Aug 17, 2017

@jnsebgosselin Thanks for your contribution, It looks pretty good

Question, why did we need to create a new class on top of the base editor?

I agree with @goanpeca, I think we could use other approach instead of adding a new layout of inheritance to the CodeEditor

A solution maybe out of the scope of this PR:
I like the idea of how pyqode split the functionality in different "Modes" (I'll call them something like editor features), they are pluggable classes, like the panels, that keep reference to the CodeEditor, and implement methods that are fired according to CodeEditor events

something like this:

class MultiCursorsEditorFeature(EditorFeature):
     def _on_key_pressed():
          ....
     def _on_key_released():

     def register_editor_feature():
           self._editor.sig_key_press.connect(self._on_key_pressed)
           self._editor.sig_key_press.connect(self._on_key_pressed)

class CodeEditor():

    def __init__(self):
         editor_features = EditorFeaturesManager
         editor_features.register(MultiCursorEditorsFeature)

    def KeyPressEvent(self, event):
         self.sig_key_press.emit(event)

You could take a look at some pyqode modes https://github.com/pyQode/pyqode.core/blob/master/pyqode/core/modes/autocomplete.py

We will need to create a EditorFeaturesManager() and EditorFeatures() (we already have pyqode Mode that we use for panels) I think we could reuse some panels logic and It wont be really hard to implement.

@ccordoba12 @goanpeca What do you think?

@goanpeca
Copy link
Member

@rlaverde sounds good. But what to do in the meantime :-p

@rlaverde
Copy link
Member

But what to do in the meantime :-p

I don't know, putting more code in the already complex CodeEditor doesn't seem as a solution 😞

@ccordoba12
Copy link
Member

We will need to create a EditorFeaturesManager() and EditorFeatures() (we already have pyqode Mode that we use for panels) I think we could reuse some panels logic and It wont be really hard to implement.

I really like this idea! @rlaverde, could you implement this so that @jnsebgosselin can use it to implement this feature?

@rlaverde
Copy link
Member

Which name should I use? Modes? EditorFeatures? any other suggestion?

@jnsebgosselin
Copy link
Member Author

This looks neat! I like the way it is possible to easily turn off or on modes with that approach.

@ccordoba12
Copy link
Member

Which name should I use? Modes? EditorFeatures?

I think Features is enough. Since everything related to a plugin is going to live under the same directory after we merge split-plugins, I think there's no need to be more explicit.

@ccordoba12
Copy link
Member

@jnsebgosselin, please rebase this PR and use @rlaverde's new Editor extensions to implement this feature.

@jnsebgosselin jnsebgosselin self-assigned this Oct 10, 2017
@ccordoba12
Copy link
Member

@jnsebgosselin, @rlaverde can finish this one. Do you agree?

@jnsebgosselin
Copy link
Member Author

@ccordoba12 Sure thing.

@ccordoba12
Copy link
Member

@rlaverde, please make this an Editor extension and add tests for it.

@CAM-Gerlach CAM-Gerlach changed the title WIP: Add multiline editing capability in the Editor PR [WIP] Add multiline editing capability in the Editor Feb 18, 2018
@CAM-Gerlach CAM-Gerlach changed the title PR [WIP] Add multiline editing capability in the Editor PR: [WIP] Add multiline editing capability in the Editor Feb 18, 2018
@CAM-Gerlach CAM-Gerlach changed the title PR: [WIP] Add multiline editing capability in the Editor [WIP] PR: Add multiline editing capability in the Editor Feb 18, 2018
@goanpeca goanpeca added this to the Sprint May milestone Apr 28, 2020
@goanpeca goanpeca force-pushed the multiline_editing branch 4 times, most recently from cab35e3 to 114e735 Compare April 29, 2020 00:54
@jnsebgosselin
Copy link
Member Author

This work is pretty cool @jnsebgosselin, @dalthviz will squash the commits (to 1 to make it easy to rebase) and then rebase it with master so we can try to use this PR.

Will also add some tasks on the description as @dalthviz @juanis2112 and @steff456 will continue this work. Thanks a lot!

Oh great, I thought this would be useless, so I'm happy if this helps! I'm sorry I haven't had time to look at this to try to help you further but at this point, I did this so long ago that I don't remember anything lol

@goanpeca
Copy link
Member

Oh great, I thought this would be useless, so I'm happy if this helps! I'm sorry I haven't had time to look at this to try to help you further but at this point, I did this so long ago that I don't remember anything lol

What you did works just fine!, the extension logic on the editor (that we borrowed from pyqode project) has remain intact, so all the work is completely on track to be reused and completed.

I also forgot about this as well, but after reviewing your work again, it all made sense, so thanks again, and no worries :-p

@ccordoba12 ccordoba12 modified the milestones: Sprint May, Sprint June Jun 1, 2020
@ccordoba12 ccordoba12 modified the milestones: Sprint June, Sprint July Jul 2, 2020
@ccordoba12 ccordoba12 modified the milestones: Sprint July, v5.0alpha2 Aug 5, 2020
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha2, v5.0alpha3 Nov 12, 2020
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha3, v5.0alpha4 Jan 8, 2021
@brupelo
Copy link

brupelo commented Feb 5, 2021

@jnsebgosselin I must to say I'm impressed, really promising PR/WIP you've created over here! one question, when undoing/redoing... will the multiple selections be preserved? Please take a read to see what I mean by that in this thread https://bugreports.qt.io/browse/QTCREATORBUG-16013 . I'm asking this cos one of the main weak points of Scintilla for instance is the fact that the different selections will be gone when undoing/redoing... But in proper implementations such as SublimeText, Codemirror, Monarch, etc... such selections will be preserved.

And just for the record, when I say I'm impressed I really mean it... you won't see this "must to have on a modern text editor" feature on almost any existing Qt widgets out there on all github... so... hats off :) . Pasting some references I've found over time regarding to this subject in case it helps:

Text editors
------------

https://github.com/ajaxorg/ace
https://github.com/andreikop/qutepart
https://github.com/awm/synhtor/wiki/Research
https://github.com/codemirror/CodeMirror
https://github.com/edbee/edbee
https://github.com/edbee/edbee-app
https://github.com/edbee/edbee-data
https://github.com/edbee/edbee-examples
https://github.com/edbee/edbee-lib
https://github.com/githole/Live-Coder
https://github.com/howl-editor
https://github.com/hydrargyrum/eye
https://github.com/JuBan1/notepadqq
https://github.com/JuBan1/OpenTextEdit
https://github.com/kai66673/PythonEditor
https://github.com/luchko/QCodeEditor
https://github.com/lukedan/codepad
https://github.com/martinrotter/textosaurus
https://github.com/matkuki/ExCo
https://github.com/prymatex/prymatex
https://github.com/pybee/seasnake
https://github.com/pyQode/pyqode.core
https://github.com/richrd/suplemon
https://github.com/SergeySatskiy/codimension
https://github.com/smathot/QProgEdit
https://github.com/spyder-ide/spyder
https://github.com/trishume/syntect
https://github.com/tsujan/FeatherPad
https://github.com/waddlesplash/Heidi
https://kate-editor.org/
https://sourceforge.net/projects/synwrite

Text rendering
--------------
https://learnopengl.com/In-Practice/Text-Rendering
https://wdobbie.com/post/gpu-text-rendering-with-vector-textures/
https://medium.com/@evanwallace/easy-scalable-text-rendering-on-the-gpu-c3f4d782c5ac
http://jcgt.org/published/0006/02/02/
https://blog.mapbox.com/drawing-text-with-signed-distance-fields-in-mapbox-gl-b0933af6f817
https://aras-p.info/blog/2017/02/15/Font-Rendering-is-Getting-Interesting/
https://medium.com/@calebfaith/implementing-msdf-font-in-opengl-ea09a9ab7e00
https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch25.html
https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf
https://wildfiregames.com/forum/index.php?/topic/17365-freetype-ttf-fonts-in-opengl/

https://github.com/rougier/freetype-gl
https://github.com/servo/pathfinder
https://github.com/Chlumsky/msdfgen
https://github.com/behdad/glyphy
https://github.com/0ad/0ad
----------------------------------------

Your implementation reminds me to https://github.com/JuBan1/OpenTextEdit ... cool stuff :D

@ccordoba12 ccordoba12 modified the milestones: v5.0alpha4, v5.0alpha5 Feb 14, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha5, v5.0alpha6 Feb 23, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha6, v5.0beta1 Mar 19, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0.0, v5.x Apr 2, 2021
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 multiline editing to the Editor
7 participants