Show HN: Primrose – A text editor that draws to Canvas
capnmidnight.github.io
capnmidnight.github.io
This is an easy one to solve, it just takes a moment to pick a real license for your project[1]. Real licenses are more than one sentence long because there are real issues that both licensor and licensee need to understand before they can go forward.
Caveat: Carota does not solve Right-To-Left text or complex scripts, and I'd really appreciate help with that. It's the only blocking issue against me using it in my main work project.
(By a strange coincidence I use the codename Primrose in an unrelated project...)
Doesn't seem to support a lot of common ways I edit text, like holding shift and using arrow / alt-arrow to select. Selecting and hitting delete. Selecting with the mouse and hitting delete doesn't work.
"works in Chrome" is just all the further I've gotten so far in a weekend. I can eventually get it to work in Firefox, just need a little more time to build out the features.
Unfortunately, I'm not out to make a tool for everyone in the world. No, I don't have a plan for those issues, but I and at least one other person I know have need for text editing in a WebGL context (specifically, with WebVR work). For that, I need a canvas element that I can make into a texture.
The only previous work towards such a thing I could find was a Kickstarter that failed to deliver (https://www.kickstarter.com/projects/1241383920/open-source-...). The current status is that there is no way for any locale to have even antiquated ASCII text, highlighted, and working with editor controls, in a WebGL context.
I've done a bit of tinkering with a variety of modules for word-wrapping, etc. None of them are "fully featured" or 100% stable but I have used them in a couple of production environments.
https://github.com/mattdesl/fontpath
The WebGL module on top of that:
https://github.com/mattdesl/gl-sprite-text
The main issue I have with most text libraries (like TxtJS) is that they assume 2D canvas, or trivial WebGL applications. The bulk of the text code really just deals with laying out rectangular glyphs; the rendering (whether geometry, bitmaps, SDF, etc) should be separate so the dev can choose the best technique for their app.
An example of SDF / fontpath in action:
Great result for a weekend still :)
(it also hijacks ctrl+f/ctrl+c/… anywhere on the website and just inserts the letter instead of calling the browser function)
All this makes me wonder whether this is the right approach and whether this couldn't be done with a lot less hassle with CSS formatting.
My code already uses a rudimentary code page system, just because it's impossible to go from DOM keyCodes to the correct text for even US keyboards, so in the long run this should be easily fixable.
It was something he and I discussed a few months ago and this was the first chance I had to work on it.
This is not going to be anything approaching the complexity of something like Vim. Think more like Notepad2. I spent basically the last 20 hours putting together this POC just to see if the rendering was even going to be clean enough to bother going further. And it looks like it is!