Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define message methods for SharedBuffer instead of Buffer #3588

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthias314
Copy link
Contributor

AddMessage and the like are defined for Buffer although they only use the SharedBuffer part. This PR defines them for SharedBuffer. As a consequence, these methods can now be used from within the onBeforeTextEvent callback, which receives a SharedBuffer as argument.

@usfbih8u
Copy link
Contributor

As a consequence, these methods can now be used from within the onBeforeTextEvent callback, which receives a SharedBuffer as argument

With this PR, how a plugin can differentiate between a text event in the buffer and a message added?

@matthias314
Copy link
Contributor Author

matthias314 commented Feb 26, 2025

What exactly do you mean? Everything that a plugin could do without this PR is still possible with it.

OK, now I believe I know what you mean. The idea is that text events can trigger messages. For example, the bookmark plugin uses messages to define bookmarks. Currently, it needs a lot of code to adjust the position of those bookmarks when text is added or deleted. With onBeforeTextEvent, this becomes much simpler in my opinion. See the proof of concept here.

@usfbih8u
Copy link
Contributor

I misread your first message.

What I was asking was whether adding a Message, etc., now triggers the onBeforeTextEvent() callback.

Now I see that what you are doing is checking if the text events are affecting your bookmarks (by moving them through removing/inserting lines, etc.).

@dmaluka
Copy link
Collaborator

dmaluka commented Mar 9, 2025

Looks like a whack-a-mole approach. I.e. what about any other Buffer methods that onBeforeTextEvent may want to use?

This shows once again that this onBeforeTextEvent interface is poorly thought out (so it's a good thing that we still haven't documented it), OTOH I don't know what interface to replace it with...

@matthias314
Copy link
Contributor Author

I agree that it makes sense to reconsider onBeforeTextEvent. Nevertheless, from the point of view of code hygiene, shouldn't methods that use a SharedBuffer be defined for SharedBuffer instead of Buffer?

@dmaluka
Copy link
Collaborator

dmaluka commented Mar 9, 2025

I have a counter-question: are we sure that Messages really belongs in SharedBuffer, not in Buffer?

And same about Suggestions, Completions, many of Settings (such as ruler, softwrap and so on)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants