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

Feature: Register commands with update options #6767

Closed
landisdesign opened this issue Oct 26, 2024 · 3 comments · Fixed by #6773
Closed

Feature: Register commands with update options #6767

landisdesign opened this issue Oct 26, 2024 · 3 comments · Fixed by #6773
Labels
enhancement Improvement over existing feature

Comments

@landisdesign
Copy link
Contributor

Description

Allow the third argument to editor.registerCommand() to take an object that includes the priority as well as the update options. registerCommand() could then be called as follows:

editor.registerCommand(COMMAND_NAME, commandFunction, COMMAND_PRIORITY_LEVEL);

or

editor.registerCommand(COMMAND_NAME, commandFunction, {
  discrete: true,
  onUpdate: // post-update function,
  priority: COMMAND_PRIORITY_LEVEL,
  skipTransforms: true
});

This would let us manage the command with more finesse, in situations where we need to use these options to narrow the scope of the command's changes.

For my current use case, I have an update listener that submits user input to the server. I also have a command that updates the editor with data from the server. While the command is operating, I don't want the listener to be active, or else it creates a feedback loop.

Currently I'm setting a flag in the command, and the update listener knows not to send to the server while that flag is set. I want to be able to unset the flag in an onUpdate callback function, but can't do so directly in the command. Right now I queue a microtask to do so, but that seems "unLexical."

@landisdesign landisdesign added the enhancement Improvement over existing feature label Oct 26, 2024
@etrepum
Copy link
Collaborator

etrepum commented Oct 26, 2024

I think the biggest issue here is that you can register multiple listeners for the same command and it doesn't always make sense to combine these sorts of options (skipTransforms and discrete aren't very composable, if any update has them then its effect happens for all updates in that batch).

Having it be possible to add an onUpdate from within an update makes sense, I think a better solution for that would be to have a dollar function to do that. The implementation would be basically function $addOnUpdate(fn) { $getEditor()._deferred.push(fn); }

@landisdesign
Copy link
Contributor Author

That makes sense. Should this be closed and the $addOnUpdate proposal be introduced in a new ticket?

@etrepum
Copy link
Collaborator

etrepum commented Oct 27, 2024

I don't think a new issue needs to be created, if you wanted to create a PR for it with a test then it would probably happen quickly. I didn't think too much about the name, maybe $onUpdate or $afterUpdate would be more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement over existing feature
Projects
None yet
2 participants