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

getValue() returns old value after search & replace function #46

Open
sirbris opened this issue Jul 12, 2024 · 3 comments
Open

getValue() returns old value after search & replace function #46

sirbris opened this issue Jul 12, 2024 · 3 comments
Labels
awaiting answer Awaiting the answer of the creator of the issue/feature request.

Comments

@sirbris
Copy link

sirbris commented Jul 12, 2024

After using search & replace in your editor, the getValue() method returns the old value... would it be possible to trigger a valueChange event after user replaced text via that function or any other method to get the real client side value?

@F0rce
Copy link
Owner

F0rce commented Jul 19, 2024

Hi @sirbris,

Sorry for the late reply.

Unfortunately the search & replace functionality is completely provided by ace. So there is no way to create a custom hook etc.

But I think it is still possible to work around this.

Some time ago the AceChangedEvent was introduced in #21. Maybe, just maybe, you can get the value by registering the AceChangedEvent (which will send a lot of data) as soon as someone hits ctrl + f, wait until all the changes are done (maybe through a debounce function or something like that) and then unregister the AceChangedEvent.

If that's not possible or doesn't work the way I thought it would, it would require a major change to the lit-ace frontend and the @f0rce/ace-builds repo (because the ace editor has some custom functionality like the status bar, etc).

Please let me know if this has pointed you in the right direction or solved the problem.

Take care,
David

@F0rce F0rce added the awaiting answer Awaiting the answer of the creator of the issue/feature request. label Jul 19, 2024
@F0rce
Copy link
Owner

F0rce commented Jul 19, 2024

If that doesn't work you could take a look at the sync functionality. I wouldn't know when to use it (as how would you know that a user finished replacing), but it is defined here

/**
* Forces a sync between client and server without blurring. Use {@link
* #addSyncCompletedListener(ComponentEventListener)} to get the values after the sync completed.
*/
public void sync() {
this.getElement().callJsFunction("forceSync");
}
/**
* Add a listener to the editor, which listens to when the sync event completed, which is
* triggered by the {@link #sync()} method. Check {@link AceForceSyncEvent} for all availible
* returned values.
*
* @param listener {@link ComponentEventListener}
* @return {@link Registration}
*/
public Registration addSyncCompletedListener(ComponentEventListener<AceForceSyncEvent> listener) {
return this.addListener(AceForceSyncEvent.class, listener);
}

@lucaschraml
Copy link
Collaborator

Works if you do a server roundrip afterwards.

So in my case i made somthing like this

public class MyAceEditor extends AceEditor {

@ClientCallable
public boolean roundtrip() {
return true;
}

}

and called it by the executeJs() method on the AceEditor object

aceEditor.sync();
aceEditor.getElement().executeJs("document.getElementById('yourAceEditorId').$server.roundtrip()").then(event -> {

//do what you want to do with the new value :)
System.out.println(aceEditor.getValue());

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting answer Awaiting the answer of the creator of the issue/feature request.
Projects
None yet
Development

No branches or pull requests

3 participants