GithubHelp home page GithubHelp logo

Comments (7)

lukewilliamboswell avatar lukewilliamboswell commented on July 28, 2024 2

Got something minimal to share and seeking some direction - opening a file from arguments, rendering the text contents to a window.

I've included a super simple implementation of a Piece table which looks to be the easiest way to build a text editor.

I've also used the text segmentation from roc-lang/unicode to split the input file into graphemes so in theory this should support unicode out of the box 🀞

So far the demo only renders text, the editing and saving functionality hasn't been included yet.

I'm pretty sure the undo/redo will be essentially free. The plan is to just keep a new copy of the Piece Table (sans buffers) on each significant user action (edits) in a list. This is just duplicating the indexes into the buffers and so shouldn't grow too significantly unless the user has very long editing session. We can always just keep the latest N edits or something if it becomes a problem.

WIP code for this demo (I haven't removed any of the code from the menu example, just added the parts for editor)

Questions

  1. Do you think it is acceptable to render newlines just using "ΒΆ", this dramatically simplifies the code code. Though if we want to include line numbers then we will need to handle CLRF breaks anyway?
  2. Do we want multiple "pages", like a menu or something, or keep it simple an just open straight into the editing window?
  3. Do we want multiple "modes", like vim, command and insert and support different controls in each? This should be pretty easy to support, maybe just a couple of the basics.

Demo

roc-editor-1

from book-of-examples.

lukewilliamboswell avatar lukewilliamboswell commented on July 28, 2024 1

Quick update on progress this weekend.

WIP code branch

  • handle line breaks
  • remove unused code from previous example
  • implement a ViewPort to draw the content (was helpful for testing edge cases, may be useful in future for e.g. editing multiple files)
  • enable saving of changes using Ctrl-S keypress
  • add text insertion (and implementation for the PieceTable data structure)

I've had to make a few changes to the roc-ansi package, so this has been good to flush those issues out and resolve them.

I've also been adding a lot of inline comments and thinking about the dot points for the chapter content.

Demo

roc-editor-2

from book-of-examples.

gvwilson avatar gvwilson commented on July 28, 2024

πŸ‘ to a simple text editor - I found with the Python version that mapping various coordinate systems to each other and handling basic keyboard input was one chapter, while adding undo/redo was another. Don't know if it would be the same here?

from book-of-examples.

gvwilson avatar gvwilson commented on July 28, 2024

This is a great start - well done! I based the editor in the Python book on the first few parts of Wasim Lorgat's tutorial https://wasimlorgat.com/posts/editor.html - I think we definitely want the line breaks, but modes and windows and what-not won't fit into the one-hour limit.

from book-of-examples.

gvwilson avatar gvwilson commented on July 28, 2024

this is great work - thank you very much. I think you may already have an hour's worth of teachable material - if you'd like to grab some time with me ([email protected]) I'd be happy to talk you through next steps.

from book-of-examples.

lukewilliamboswell avatar lukewilliamboswell commented on July 28, 2024

Sounds good. I sent you a meeting request via email. Just took a guess at a suitable time re timezones. Apologies if it's too short notice, I could find a time next week.

I'd like to implement text deletion to close out the Piece table basics. Also I'll need to make a release for the unicode and ansi dependencies before this will be usable more generally.

If you don't mind I'd love to write something up about this for my blog and share in the online meetup this weekend, it won't be the same content as the book more my experience.

from book-of-examples.

gvwilson avatar gvwilson commented on July 28, 2024

Blogging about this would be great, and no worries about overlap with whatever you're going to write for the book: you own the rights to your blog posts, so you can decide to recycle them.

from book-of-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.