Callback sent to `(TextEditor).onDidStopChanging` is called upon every keystroke, more or less

I’m not sure I understand exactly what behavior from this function is desired, but the documentation suggests that its callback is called —at least —a little bit more infrequently than upon every keystroke :slightly_frowning_face:. It would be great to have a means to easily run code when the user takes a break from typing.

1 Like

Yeah, I think (could be wrong) that onDidStopChanging has a hardcoded value for the amount of time delay before it considers changes to have “stopped”. The delay is pretty short, almost instantaneous to the human eye if you’re not paying attention to it.

Would really be helpful for developing issue provider extensions if the onChange time delay was exposed/configurable in the relevant APIs.

Perhaps a better alternative would be to make it a configurable preference so that end-users can globally set their preferred onChange time delay and extension devs don’t have to worry about (mis-)implementing such behavior.

I think the problem occurs only if the callback is registered several times. The extension I’m working on must be doing so, although that is unintentional.

Screen Recording 2022-05-23 at 14.03.10

I fixed the bug that caused several event listeners to be registered. Still, the issue continues. It’s hard for me to deduce under which conditions this happens exactly.

The amazing new Tools extension can be used to test this. Create a new tool with these contents:

tool = {
	id:"changetool",
	name: "onDidStopChanging Event Listener",
	onAction: () => {
		nova.workspace.activeTextEditor.onDidStopChanging(() => {
			const request = new NotificationRequest();
			request.title = "Stopped Changing";
			request.body = "Nova called the onDidStopChanging callback. Had you actually stopped changing?"
			nova.notifications.add(request);
		});

		const request = new NotificationRequest();
		request.title = "Added the Callback";
		request.body = "This editor is being watched for changes.";
		nova.notifications.add(request);
	},
	onSave: () => {}
};

Then, open an editor. Double click on the tool’s name in the sidebar, and observe the appearance of notifications. When I do this, a new notification is sent immediately after the addition of any non-whitespace character.