r/macosprogramming • u/p_bzn • Apr 20 '24
How would you approach creation of a text editor similar to Notion?
Goal: create a text editor which
- Supports basic editing and formatting operations, somewhat close to markdown
- Supports context menu, when you type `/` character some menu appears at the position of the text cursor
- When a certain events happen autosuggestion appears at the position of the cursor
- Parts of text can be selected and context menu with custom logic can be called on them
- Drag and Drop media like images
Gaps I see:
- My understanding of text editor architecture (know how to solve)
- My experience with MacOS development in general (don't know how to solve)
The first gap is easy to fill in, there are text editors which code I can read, and even some book-like walkthroughs on writing a text editor.
Second gap puzzles me. Currently the PoC application is SwiftUI with SwiftData. I'm opened to use any other language (objc, C), but not WebView, otherwise I would go with Tauri in the first place.
Question is: how would you approach such a task? Can I build a custom view from the ground up? Is there any shortcuts I can take?
My main point of discomfort is that I don't understand how to process in terms of a view, how to make it work. I have a sound understanding how to approach that with say JS/HTML by just writing a data structure of blocks and strings, render views, attach listeners, etc. With MacOS I just don't understand how to start.
Any suggestions and pointers are super welcome!
2
u/neoreeps Apr 20 '24
I'd look at obsidian then write a plug-in for whatever it's missing. It's truly amazing.
2
u/david_phillip_oster Apr 22 '24
Apple's own text view provides all the building blocks you need for writing something like this
UITextView has a layoutManager , a textStorage , and a textContainer sample code: https://developer.apple.com/documentation/uikit/textkit/display_text_with_a_custom_layout and https://developer.apple.com/documentation/uikit/textkit/using_textkit_2_to_interact_with_text
1
u/robvas Apr 21 '24
Start by writing a plain jane text editor
https://www.averylaird.com/programming/the%20text%20editor/2017/09/30/the-piece-table.html