Skip to content

[Proposal] Refactor of View/Buffer #515

Closed

Description

@samdmarshall

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:


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

  1. zyedidia commented on Jan 1, 2017

    @zyedidia
    Member

    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.

  2. NicolaiSoeborg commented on Jan 30, 2017

    @NicolaiSoeborg
    Contributor

    For plugins (e.g. issue #249) it would be nice with an "readonly" settings for buffers.

  3. samdmarshall commented on Feb 7, 2017

    @samdmarshall
    ContributorAuthor

    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.

  4. DanielPower commented on Feb 7, 2017

    @DanielPower
    Contributor

    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.

  5. samdmarshall commented on Feb 8, 2017

    @samdmarshall
    ContributorAuthor

    @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.

  6. zyedidia commented on Feb 8, 2017

    @zyedidia
    Member

    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.

  7. samdmarshall commented on Feb 8, 2017

    @samdmarshall
    ContributorAuthor

    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.

  8. zyedidia commented on Feb 17, 2017

    @zyedidia
    Member

    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 CellView object 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.

  9. zyedidia commented on Mar 27, 2017

    @zyedidia
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions