Repository navigation
Description
After looking over the list of open issues and the current code off master (for real this time), I'm wondering if there might need to be an abstraction or refactor of how the View/Buffer code is written to handle a few more features. From my understanding, the Buffer code is setup such that it reads in a file, splits the contents into an array of lines. Then the user will interact with those lines through an interface. The display of those lines is handled by the View code. The View code will display lines as soft wrapped or not based on the content of the Settings code. Since there is (currently) no way to correlate between the line number that one is editing in a text file, and the row of the terminal that the cursor is on (that is doing the editing); it makes issues like #498 (Up/Down navigation ignores softwrap) impossible to implement.
This is a product of the very clean and segregated code that micro has (kudos!). However I am wondering if the editor as a whole wouldn't benefit more from the introduction of a new interface that manages the display of the lines of the buffer. At a high level, the View and Buffer code functionality would be retained as is, but create a new interface used that maps the lines to be displayed and how that corresponds to the columns/rows of the tcell display on the terminal. This would add another layer of abstraction between displaying the content and what the display is backed by.
This proposed change would incur a new level of complexity that hasn't existed before in the code, however I believe this would be a worthwhile trade off:
- Limiting the drawing of only visible content (Crash on huge files #279 and Handling of larger files is poor #468)
- Classification of buffers (readonly vs readwrite) -- Help and Log buffers could be marked as "readonly", and not accept input from the user.
- Navigation could be implemented in relation to the rows and columns of the terminal display (Up/Down navigation ignores soft-wrap #498, and the myriad of multiple cursor issues/PRs)
- Since the display is more refined, it would be possible to have more control over display of wrapped text (Word wrap #264)
- Abstraction between display and content of the display would make it easier to show custom UI via plugins (Suggestion: tree view file browser sidebar #249)
That said, I am honestly unsure of how I would go about doing this without it feeling like a kludge or hack-job. Since this would be a non-trivial change to the code-base and functionality, it should be something that the community has discussion about before anyone goes to implement. What are y'all's thoughts?
Activity
zyedidia commentedon Jan 1, 2017
Yeah I have been thinking about refactoring the code, especially
view.go. As micro has grown, the view code has gotten somewhat messy (especially with things like softwrap) and I think everything you have outlined here is great. I'm going to have more free time soon and my primary goal is going to be to clean things up a bit.NicolaiSoeborg commentedon Jan 30, 2017
For plugins (e.g. issue #249) it would be nice with an "readonly" settings for buffers.
samdmarshall commentedon Feb 7, 2017
I'm going to bump this as I am looking at creating a plugin for giving micro some IDE-esque functionality for Nim-Lang using some of their existing tooling. Part of what is holding me up is designing around the current UI constraints that micro has -- using the status bar and/or message bar to display completions and doc-strings. Being able to jump to file definitions seems doable, but right now I'm not sure about being able to use the mouse for that. Trying to work out if i should hold off on this until the refactor of the view/buffer code that was mentioned by @zyedidia is done or proceed for now using the existing APIs.
DanielPower commentedon Feb 7, 2017
If your main issue is that you need your plugin to take mouse input, I'm going to be working on implementing that when my semester break comes up in a couple weeks.
I'm not 100% sure how it's going to work at the moment, since I need to figure out how exactly event data is passed to CurView. So I'm not sure if I'll be able to pass to the plugin which view was clicked as well as the (x, y, button), or if I will be able to only pass the (x, y, button).
I'm doing this for the purpose of improving the FileTree plugin that's currently a work in progress. So that you can click on items in the FileTree the same way you would in a graphical IDE like Atom or Sublime.
samdmarshall commentedon Feb 8, 2017
@DanielPower the mouse interaction isn't my primary concern, but before I undertake anything I would like to know how the existing refactor plans are timelines and what i could expect to be working with at the end of them.
zyedidia commentedon Feb 8, 2017
I don't have much time at the moment so I don't expect to do this refactor too soon (maybe in a month or two). I think if you're interested in adding some sort of functionality right now you should go ahead with it.
samdmarshall commentedon Feb 8, 2017
I'm happy to give a stab at some of this but timeline to get it upstream makes me hesitant. I'm willing to wait and see what you have planned (being the more experienced Go programmer) at this point.
Edit: Also I have a couple of open PRs already, and I'd not pile up on that without knowing what is going upstream or not.
Add beginning of cellview as well as improved ViewTypes
Add beginning of cellview as well as improved ViewTypes
zyedidia commentedon Feb 17, 2017
I plan to do this refactor in two parts. The first part is to refactor to make displaying the view more efficient. The second part is to use the new
CellViewobject created to make drawing more efficient to also fix various issues like moving on soft wrapped lines.I have started on the first part of the refactor already, although it's not complete by any means. I also am currently rewriting the syntax highlighting engine. The new version will have a concept of regions, which fixes issues like #374 or #217. It will also be much faster and more memory efficient.
Add beginning of cellview as well as improved ViewTypes
Add beginning of cellview as well as improved ViewTypes
zyedidia commentedon Mar 27, 2017
I think this can be closed now that #593 has been merged. Even if the softwrap improvements haven't completely been made, it should be easier now and the view refactor itself is finished.