SidneyNemzer / elm-text-editor

A text editor written completely in Elm
https://sidneynemzer.github.io/elm-text-editor/
79 stars 14 forks source link

Add primitive scrolling feature, copy, cut, paste #5

Open jxxcarlson opened 4 years ago

jxxcarlson commented 4 years ago

Beautiful code! Have been studying it and have made some additions, most importantly a scrolling feature.

Scrolling is managed by the module Window which determines the range of lines of text that is visible to the user. One can scroll up and down using a slider, or using the up and down arrow keys.

I've also implemented primitive copy, cut, paste: ctrl-c, ctrl-x, ctrl-v and a few other goodies: first and last line, go to specific line, wrap text, search and replace. There is also an external copy-paste feature. Please see the "Help" button in the Editor (and scroll down) for an explanation.

Please see the Basic Editor Demo.

I think that with a reasonable amount of work, a 1.0 version of the editor could be published soon as a package. I'd certainly be one to use it, and I"m sure that there would be many others.

If you are agreeable to it, I'd be very interested in contributing to your project. Looking forward to discussing this with you.


Notes. The purpose of some of the later commits is to reduce the amount of wiring that a user of this code needs to install to integrate the Editor in an app. I've outlined the steps (with one caveat) in Embedding.md. Everything in a client app is done using functions that operate on the Editor data structure in module Editor. The Editor type is opaque and incorporates both Buffer and InternalState.

To use the Editor in an app, one first says

import Editor exposing (EditorConfig, Editor, EditorMsg)
import Editor.Config exposing (WrapOption(..))

then adds an Editor field to the app model, initializing it by

editor = Editor.init config "Some text"

where config: EditorConfig Msg holds configuration data, e.g. the number of lines to display in the editor, the width of the editor window in pixels, etc.

Here is an example of integration of the Pure Elm Text Editor with another app: MiniLaTeX Demo.

Caveat. The external-copy paste feature requires some JS code (inoutside.js) and also a module Outside in the app that hosts the Editor. I haven't documented this yet, but you can see how it is set up in the demo.


Additional Note. Just wanted to send you a copy of my DM to you on the Elm Slack today, January 10, 2020. Best regards, Jim

jxxcarlson: 1:41 AM Hi Sydney, since I haven’t been able to reach you,I decided to go ahead and publish my fork of your package. I give full credit to your work, which is really a joy to work with. Very best regards, Jim. I’ll post the link as soon as it is up

jxxcarlson: 1:55 AM Here is the package link: https://package.elm-lang.org/packages/jxxcarlson/elm-text-editor/latest/ Please feel free to use any of the code in the repo. If there is a way we could collaborate that would be great.

SidneyNemzer commented 4 years ago

First, I just want to apologize for taking so long to see this... I guess GitHub didn't notify me since I wasn't watching the repo. Funny enough, I saw your posts on discourse.elm-lang.org but I didn't realize you had opened a PR.

I'm really glad you've been able to build on my code, it looks like you've added some great features! Unfortunately, I don't have time to dedicate to Elm projects, although I hope that will change one day. I'll leave this PR open in case I ever get around to reviewing/merging it.

jxxcarlson commented 4 years ago

Thanks so much for your comments -- great to hear from you. I've learned so much from your code!