I wrote an addon for the text editor long time ago to make my life easier when i was coding in the text editor. pistiwique_pie_text_editor
I just updated it by merging 2 addons.
The version is for Blender 2.79 but i’d like to update it for Blender 2.8.
Looks like activate_init only works when called by bpy.ops.wm.call_menu(), so I guess it only works for popups, sadly. I used it when I tried to make a search popover in the past, but gave up since blender doesn’t really support persistent ui popups through python yet.
Speaking of search operator, there are things that could have been better both UI wise and functionally (don’t worry, it’s not a laundry list, just some observations I’ve made in the past).
It needs a way of choosing search directions
A non-1996 way of handling when no matches are found
ie. not throwing a total of 3 errors (status bar, popup and in system console)
The eyedropper icon next to the search text needs to go. There is nothing we are “sampling”.
All of the sub-operators find_set_selected need to go. The main operator covers their usage.
Wrap search needs to always be on by default. “Darn it, forgot to turn wrap off” said absolutely no-one ever. In fact, it should be called “Loop”, because “Wrap” has a different meaning in a text context.
Case property needs to be an icon depicting two As, (eg. “Aa”), or called Case Sensitive.
not reading through the whole thread so this may have been mentioned before- but the reason why I don’t and will NEVER use the text editor in Blender is because of how Blender’s window manager handles area focus. Most modern apps require you to click in an area to ‘activate’ it, but blender lets you just hover over to change the context.area, which means in a text editor if you bump your mouse and accidentally send it over into the terminal or outliner- you’re firing off hotkeys for who knows what rather than typing code.
Unfortunately, I don’t think developers will dwell on the text editor. It had to be created to tinker with a few lines of code, not to create a complete addon.
But at least we can improve it a little bit via Python
Actually text entry boxes have typing focus no matter what area the mouse cursor is above and it can be stopped by clicking outside of the typing focus area(the same behavior would be nice to have in the text editor, but again we need someone who can code in C to lift that code fro the text widget into the text editor):
In this example I’m typing without stop, notice the mouse position when letters are added:
Technically speaking, blender allows this using modals to block input in different areas. The event system outputs full ascii and makes it pretty seamless (it’s literally just event.ascii straight into bpy.ops.text.insert()).
If it’s a good idea, however, is a different matter. Blender’s context paradigm being built around following the mouse cursor.
if that got fixed I’d be much more inclined to use blender’s text editor for one-off simple scripts rather than firing up vscode. If they can fix it for the text editor they should also fix it on the terminal window too- I actually run into this problem with the terminal FAR more frequently than the text editor since it’s so small by default and easy for the mouse to move outside the area’s bounds
Here’s an alternate UI take on selection and preview of Python Templates(just a mock up). Unfortunately Blender widgets do not have a multiline or a line wrap function.
As it is right now it installs and runs without errors initially, but right clicking in the Text Editor context menu Blender for opering the add-on doesn’t work because all of the openGL code must be rewritten. All help appreciated.
All the openGL code needs to be updated to use GPU draw instead, but when completed the Text Editor will look and feel much more like a modern text editor with mini-map, indentation marks, tabs, margin line, highlightning etc.
Stuff like auto brackets and smart_complete is working.
I came across some words the coder of Code Editor wrote about his add-on:
" So some time ago I wrote this addon to improve some Text editor functionality so I don’t have to go the external path. Nowadays I would code some of it’s parts differently and better (especially the multithreaded minimap updating) so any feedback is very welcomed. Here are the features:
Start and End with right-click in any Text-editor window (it also ends with F8 because when scripting an addon you need to reload with F8 and that is not possible because this addon is a modal operator. So you need F8 + F8 + Right-click>Start_again )
When started it adjusts the text-editor to the addon preferences, so you don’t have to set line_numbers, syntax_highlight, text_margin etc. every time you open new text-editor window (this is frustating blender behavior, these settings should be global…)
It follows blender theme colors. The default ones are bad, so here I give you a good ones so its usable:
It adds a scrollable and clickable code minimap with syntax highlighting, which fades out when window is too small. It is done in another thread and has lazy updating to not lag the text-editor (python is slow for this). It can be disabled in preferences with just setting huge Hide Panel threshold :
It adds markers to visualize indentation, and it displays the scope of defs and classes (you can see it above in the gif). The scopes could be minimized but this didn’t make it into this release because when blender crashes you would loose the hidden code parts (the lines were removed from text and stored in custom property). You can see the toggle icons when you hover over line numbers.
Autocompletes brackets and “”,‘’:
Use Alt + C for magic:
put things in lists:
evaluate expressions (it knows pi, e, phi(golden ratio) and g(grav accel)):
stringify words when cursor just after the word:
Correct Home and Shift+Home behavior. Will move to first letter of line or to the previous indent. Alt+Home now moves to the line beginning:
Make comments with Alt+D. (Remove with Ctrl+Shift+D - this one is not new):
With multiple text-files it displays tabs to quickly switch between (blender has tabs but does not use them where it should…)
All this was good enough for me not to use external editor. Multiple variables highlighting and multi-editing (like Sublime has) was planned but abandoned. Maybe if enough people will be interested I could further improve this. But I don’t see Blender addon python api strong enough to do this properly, this should be done in Blenders code for performance (like that scintilla patch)."
Here’s a test version updated for using the new gpu module. I only touched the draw code and I haven’t tested it fully, or even played around with it. You can see parts I changed here.