andreikop / qutepart

Code editor component for PyQt5
http://enki-editor.org
GNU Lesser General Public License v2.1
111 stars 30 forks source link

Multicursor feature #90

Open brupelo opened 3 years ago

brupelo commented 3 years ago

Hi, first of all let me tell you after reading this project code a bit I must to say I'm impressed, it is pretty awesome&cool :)

Why am I telling this? Thing is, I've explored almost all github for few months in order to find a standalone text editor widget for python+qt that offers similar "core functionality" than codemirror, monarch, sublimetext, vscode, atom, etc... in my experience I can tell you none of the qt attempts (not even qtcreator itself) I've found were able to reach the same level of "core features"... Why? Because implementing multicursor feature properly isn't trivial by all means.

For instance, take a look to the good old (Q)Scintilla, you'll see that widget has already attempted to implement multicursor few years ago but the whole experience is completely ruined mainly because it hasn't implemented properly undo/redo and also the feature itself is not very "consistent".

Anyway, my question to you is, how hard would be implementing the multicursor feature with undo/redo properly on qutepart? IMHO if such feature was implemented, this project would reach the "next level/milestone" and it'd probably become some sort of "reference" for the python+qt community for sure.

Btw, I'll paste here some resources I've found in the past in case it may help somehow:

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

Ps. The way codemirror implements that feature is quite nice actually.

andreikop commented 3 years ago

Hi

Your review is really impressive Qutepart isn't actively developed now. But PR which implements multicursor feature is welcome. I can not estimate how difficult it will be because never use multicursor feature in other editors.

brupelo commented 3 years ago

@andreikop Sad to hear the project isn't actively developed now, I thought it was when I was checking the commit history, prs, issues... when I read the code my first thought was the project had a lot of potential.

Regarding to implement this particular feature, if it was easy to implement it I'd certainly give it a shot but unfortunately it's not clear to me how I'd do it at a first glance. In fact, not sure if by using QTextCursor objects would be the way to go to implement it properly (with undo/redo). I guess a good first step would be that If someone has a good plan/ideas about the implementation details please just share with us, that way someone (myself included) could give it a shot.

andreikop commented 3 years ago

Try to implement undo-redo with methods beginEditBlock(), endEditBlock() You call beginEditBlock(), then do a series of edit operations and call endEditBlock(). All operations are recorded as single operation. I don't know how to draw multiple cursors. Probably by re-implementing paintEvent(). See how indentation markers and whitespaces are drawn.

brupelo commented 3 years ago

Yeah, sounds about right, probably paintEvent() should be the proper place where you'd multiple cursors draw logic should be. You can see in one of the examples I've pasted above how that's done https://github.com/JuBan1/OpenTextEdit/blob/master/ote/textedit.cpp#L968-L1136 . You'll see in that code he's also using both begin/endBlock methods but not sure if you'd get the right effect when undoing/redoing as I haven't compiled/tested that code.

In any case, implementing this core feature would be awesome because once such feature was in-place you could do nice things such as implementing on top of it some sort of emulation layer of the SublimeText API, why? Because with such an API you could reuse many SublimeText commands straightaway on the widget. But again, before going that route you'd need to have this important core feature properly implemented.