Closed nicholascarroll closed 3 months ago
Looks good to me! Would be fine with enhancing the window focusing code to make it easier to use. Something I've toyed with on other projects is storing the cursor position and scroll state in the window, rather than in the buffer; that way you can open a new window with its own mark and cursor.
By the way, Score isn't an active maintainer here at the moment - no need to ping her for approval, she just helped me out early on in emsys development with a segfault I was having.
Cool. So I'll do that next.
I have implemented independed window scrolling in my branch windowScroll, and the way I did it is:
Now another disreputable design idea I have is: if this text editor is never intended to get alot more than bare bones functionality, then quite a few functions don't actually need arguments. For example, editorScroll will only ever conceivably be scrolling the currently focused window. Most stuff to do with edits and cursor movements as well.
I'm closing this and backing out the pull request because I'm not convinced its actually an improvement. While it looks nicer to me as a beginner, it does create two ways of doing things.
Hey I'm working on independed window scrolling in the switchWindows branch of my emsys fork. So that when you have two multiple windows on the same buffer you can scroll in one without the others also scrolling. And I thought "how nice it would be to have focusWin up there on editorConfig just like focusBuf?"
So....
The Idea
Let's introduce a
setWindowFocus
function, use an underscore prefix for thefocused
field in oureditorWindow
struct, and add afocusWin
pointer to oureditorConfig
. So then you can use E.focusWin and reduce code a little.Proposed Changes
Update the
editorConfig
struct:Update the
editorWindow
struct:Add a
setWindowFocus
function:Update any direct modifications of
focused
to usesetWindowFocus
instead. This is basically only when switching windows, creating or destroying windows.Keep direct reads of
_focused
(likeif (E.windows[i]->_focused)
) as they are for simplicity and performance. And not bother with a getter.Architectural Considerations
Config, focused buffer and focused window are actually singleton.
Impact of Not Doing It
just a little bit more code everywhere. It's just a convenience.
Code changes Required
the editorWindow focused property is only currently set in 3 places:
Everything else can stay the same.
What Do You Think?
If this looks good, I will prepare a PR! 😊
CC @ScoreUnder