ace icon indicating copy to clipboard operation
ace copied to clipboard

getValue() returns old value after search & replace function

Open sirbris opened this issue 1 year ago • 3 comments

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?

sirbris avatar Jul 12 '24 09:07 sirbris

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 avatar Jul 19 '24 12:07 F0rce

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 https://github.com/F0rce/ace/blob/9e6f600573492a71ee32ea2cc1e11bbd3b41adf0/src/main/java/de/f0rce/ace/AceEditor.java#L1305-L1323

F0rce avatar Jul 19 '24 12:07 F0rce

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());

});

lucaschraml avatar Oct 18 '24 15:10 lucaschraml