Better HN
topnewbestaskshowjobs
Log inSign up

hamza512b

33 karma · joined Oct 22, 2023 (3y ago) · 18 submissions

Submissions

comment 2w ago · link · parent

It is done by hand, char by char. It measures each char on a “temp” canvas, and when the line is full it goes back to the last space and breaks there. CJK can break anywhere. RTL/mixed text gets reordered per line after that. Now that I been thinking about it, I could use Intl.Segmenter for languages like Thai that don’t use spaces, but it gives word boundaries, not real line break rules. But that is how it works at least. There is a wrapText function that handles this in packages/editor/src/fonts.ts.

You might be thinking, where does the performance come from? Well, the logic I described is only run when needed. I render only the blocks you see, and recompute only what changed. Initially I thought of making it like Google Docs, with a fixed page width, but I chose this approach because if the user resizes the window, for normal documents this is still fine.

comment 2w ago · link · parent

Thanks! Fixed some of these feedback yesterday, (https://github.com/tasferlabs/tasfer/pull/42).

comment 2w ago · link · parent

This was fixed yesterday, so it should work better now. Gboard (and other mobile keyboards) do glide delete and cursor movement through selectionchange events on the hidden input instead of the usual key/input events, and I wasn’t handling those correctly.

comment 3w ago · link · parent

What choice do we have? We have to find a solution to the problem. ContentEditable is much harder to work with. This is a solution, and I hope we will at some point work out a new web API that makes these tasks easier.

Your reasoning is that I am missing out on a large percentage of users. I understand where this is coming from. I am working on mobile apps as well, as I did with iOS. I can try to close that gap even more, but I can't just switch to ContentEditable. I don't have the time, and there are already tons of projects that do that.

But if Google did it at their scale, then I think the tradeoff is reasonable, don't you think? You said in another HN post that they don't really use pure canvas. What do you mean? ContentEditable for capturing input?

comment 3w ago · link · parent

This is really valuable! Just to add a bit of context: I'm not the only one using canvas for rendering. Google Docs did it years before me. Think of it this way: I've built this almost entirely alone and still get most of the basics working.

Let's start with your test. I think the reason it struggled with the Gutenberg text is that it had a lot of images. Either way, that's a bug and it should be fixed (it shouldn't load all the images at once, and there's probably too much work happening on the main thread). I really appreciate the effort you put in.

I could also use a WebGPU or WebGL context, which would certainly be faster. I think I had a working version last year, but it had problems with blurry rendering (font hinting). I don't remember the exact details now.

Overall, I'm really thankful that you pointed these out. I'll try to work through them over the next few days. I do disagree with the premise, though: canvas is more than capable of achieving this. Performance shouldn't be an issue. That said, I agree with your points about integration with context menus and other tooling.

comment 3w ago · link · parent

I take advice and feedback like yours seriously, thank you for giving your opinion, I appreciate it. For iOS, I tried to make it work, but iOS has really made it tough in that regard. For some reason they do not like a hidden contenteditable controlled by a canvas. That is part of the reason I have an iOS app published on the App Store.

Also, I know that LLMs might sound wrong to many, and I get where this is coming from.

For me, AI gives me, as one lone developer, the power to create and implement these ideas. It helped me translate and do so much more. I agree this may create a feeling of distrust, and I don't think it should not replace thinking.

comment 3w ago · link · parent

I used radix UI, but it has no styling.

comment 3w ago · link · parent

Nice work, liked the idea. Come join Tasfer Discord, there is one there. I just added the link to it in landing page.

comment 3w ago · link · parent

If you have time, really interested on where you faced this issue, anything would help.

comment 3w ago · link · parent

WOW, I have never know that these gesture even existed. I am not big mobile user. But i will diffently look in thoses.

comment 3w ago · link · parent

Google has switched in 2020 (if i am not mistaken to canvas), but I am not saying this would be the solution to everything, It is just another option one could do. I do not know if someone noticed this, but that is part of the reason you could not just open google docs on mobile. Because I would suspected that it would been too much effort for them back than. In anyway Tasfer tried as best as possible to do that on mobile too.

comment 3w ago · link · parent

Yes, exactly that is the input surface. Canvas can not recieve the events otherwise, IME, clipboard and others events go thraugh that.

comment 3w ago · link · parent

As far as I know, Monaco, the editor behind VS Code, does not use canvas. I noticed that Google Docs uses canvas, and that was the start of my project a year ago. I think that if I had used another context, like WebGL or WebGPU, it would have been much more performant, but it is really hard to render text and parse font files that way.

Anyway, I have gotten good enough results, and I don’t think normal usage will exceed the limits of the 2D canvas.

14.

Tasfer: a text editor drawn on a 2D canvas(hamza.se ↗)

92 points · by hamza512b · 3w ago · 58 comments

15.

Show HN: One year in making, private/colleberative HTML5-canvas based editor(tasfer.app ↗)

3 points · by hamza512b · 2mo ago · discuss

16.

Show HN: A free Minecraft skin editor(hamza.se ↗)

2 points · by hamza512b · 4mo ago · discuss

17.

Neural Networks from Scratch in Python: Simpler Than You Think(hamza.se ↗)

5 points · by hamza512b · 1y ago · discuss