Tasfer: a text editor drawn on a 2D canvas
57 points - last Tuesday at 8:58 PM
SourceComments
Before anyone suggests LateX, I know, I know, but when you write collaboratively, you don't always get to choose the platform.
I like what you did here in terms of the cursor that points one way or the other: it tells you if you're in "normal" mode, or for example, in a bold region. I don't think I've seen that before so, if you made it up, that itself is a cool invention.
Would it even be possible to make those work with a canvas?
Enso.sonnet.io - what Iâm talking about.
(On untested.sonnet.io youâll find notes about the experiments / toys related)
But still this is an awesome project!
Also your website appears to have been written and generated entirely with an LLM. That doesnât inspire trust.
> But it also means the editor looks and behaves the same in every browser, on desktop and on phone, because nobody else is in charge of the pixels.
You say this as though it were a good thing. Itâs very much not; theyâre not supposed to be the same, they have slightly different expected renderings, and significantly different interactions.
And you canât inspect or emulate them.
âââ
First of all, Firefox under Linux. I see it renders with my chosen fonts, indicating (since youâve said youâre using 2D canvas) that youâre using fillText. Good; I would complain more about the alternative. But it does kinda go against a lot of what you said about who was in charge of the pixels.
I use my Compose key. Underlined · placeholders, proper replacement, &c. Huh, youâve surprised me by actually handling that correctly. Well done.
Though I do note that when I type U+1F928 FACE WITH ONE EYEBROW RAISED in a title, in the appâs sidebar and top-of-page title it becomes U+1F929 GRINNING FACE WITH STAR EYES. Thatâs⊠not encouraging, but ultimately presumably Just a Bug.
I switch to Telugu and type âteluguâ, à°€à±à°Čà±à°à±. Uh oh⊠with each new consonant it drops the completed syllable, and when I press Escape at any point it deletes the composition. Utterly debilitating bug for IME usage, but ultimately fixable.
I enter some text, find that for the most part it works significantly better than I expected, even handling things like clipboards pretty well.
Then I turn to what I know it will fail, because itâs not possible to get correct universally (different platforms have different behaviours and you canât probe it; user-agent/platform sniffing would get the best results): keyboard navigation. Ugh, Ctrl+{Left,Right} is utterly wrong. I expected it to have implemented perhaps Windowsâ behaviour and Iâd complain about that, but no, itâs stopping at both the end of one word and the start of the next, which no platform has ever done. Ctrl+{Up,Down} doesnât work by paragraphs but still by line. PageUp/PageDown kinda work but the amounts they move by are just wrong, very wrong. And so on. Cursors are frustratingly non-native the while (becomes move when hovering over selected text).
I check whether Backspace seems sane on Telugu text. Seems to be, to my satisfaction. Ctrl+Backspace, of course, is utterly wrong like Ctrl+Left was.
I decide to skip testing any BiDi. But I do run through some of https://lord.io/text-editing-hates-you-too/, and watch it fail vertical cursor movement, affinity, emoji modifiers⊠meh, BiDi is here, so I decide to test it once and oh dear while it supports the general concepts properly (including selection) it seems to think that if you give it a little bit of RtL in an LtR paragraph it should turn the paragraph RtL which is badly wrong, and then it handles other aspects of selection and keyboard interaction badly wrongly. And it already failed composition. So yeah⊠it failed them all, where Firefox handles them all correctly.
I try zooming with my touchpad. Nothing happens if the cursor is over the canvas. Grr. Works but leaves the canvas blurry if the cursor is outside it. (Fixable.)
I paste the full text of Winnie-the-Pooh <https://www.gutenberg.org/cache/epub/67098/pg67098-images.ht...>. It locks up the browser tab for several seconds. (Not fundamental, but not surprising either. The browser can handle pasting a mere 26,000 words with light markup in an instant.) And takes perhaps minutes more in the background to decide it is failing to upload all the images (and regularly goes and tries to load them again later). It also inserts blank paragraphs between every paragraph and turns italics into underscore wrapping for no apparent reason. And mangles â*** START OF THE PROJECT GUTENBERG EBOOK WINNIE-THE-POOH ***â into italic â\\\\\\ START OF ⊠\\\\\*â. Not encouraging, though once again not particularly about canvas text editing.
Now the document is long enough, I try scrolling. Oh no.* Scrolljacking!? That was completely unforced error! You must use a real scrolling area. Scrolling is now utterly tedious for me, because itâs not possible to implement scrolling yourself from the events exposed to you, and whatever monstrosity itâs doing instead gets the scroll rate wildly wrong and lacks inertia, so a full swipe on the touchpad gets almost a pageful instead of several plus a hundred more if done fast. Combined with it hiding its fake scrollbar until you scroll, large documents are nigh unusable. Now once again, this is not fundamental to canvas text editing, so long as youâre willing to put the thing in a proper scroll area that you maintain.
I switch to Firefox for Android with the FUTO keyboard. Initially things seem to be working well, better than I expected, particularly given how Iâve observed the backing text input is generally only being given a word at a timeâI think FUTO must be remembering words itself for its suggestions, working around how badly broken what itâs being given is. But then I try to shift the cursor by sliding my finger along the Space key, and it doesnât work. I switch to something else and come back, and selection is shot, itâs lost the caret and I donât know what happened to it, and various keyboard interactions are broken. I press and hold on a word to select it as always works, and⊠it doesnât: no, it seems like theyâve implemented something a little more like my vague memories of iOS from when Iâve seen that; and badly at that. Correct selection is rendered tedious, unreliable, and sometimes impossible. And as for doing anything with that selection⊠it offers Copy, Cut, Paste. Utterly inadequate, stopping the browser from doing stuff with the text (e.g. share to another app), but unavoidable in the canvas approach.
At this point I give up; itâs completely unusable for anything but the basics. A lot of what I complained about is just that this is buggy and incomplete, but a lot of it is also fundamentally unfixable.
Even the buggy and incomplete parts indicate why the approach is, to put it gently, risky. But the unfixable partsâ
This is why you should only use contenteditable.
And I didnât even get to throttling my CPU to 400MHz to test performance. But itâs after half past midnight and I should be asleep already.
The 2D canvas part is the norm for anyone who wants performance. Working with the DOM becomes painfully slow and resource intensive the moment you add syntax highlighting, spell checking, and other visual chrome, to large documents.
This is why Monaco (the editor widget behind VSCode) is a canvas. Why terminal emulators built with web technologies use canvas. And so on.
So I wouldnât say the canvas part of the heading is a differentiator.
Edit: apologies, seems I was wildly wrong here. Please disregard the above.