juicy-ace-editor icon indicating copy to clipboard operation
juicy-ace-editor copied to clipboard

selects all text on every change ( when used in an Elm app )

Open nickperkinslondon opened this issue 7 years ago • 4 comments

...i fixed it by doing this: this.editor.setValue( val, 1 ); Not sure if my problem is related to Elm or not...

nickperkinslondon avatar Mar 31 '17 21:03 nickperkinslondon

Thanks for reporting :) I think it's not related to Elm, it happens in lots of our use cases.

However, I'm not sure whether it's a bug or a feature ;), as this is the default behavior of Ace editor. Simply juicyAceEditor.value = 'smth' <=> aceEditor.setValue('smth'). If you want to achieve non-default behavior you can always do as you mentioned:|

// juicyAceEditor.value = val; // without select all
juicyAceEditor.editor.setValue( val, 1 );

For sure it's worth mentioning in README. I'll try to get some closer look to the latest Ace API, maybe I'd find something cleaner.

Any other comments are more than welcome :)

tomalec avatar Mar 31 '17 23:03 tomalec

I am not sure you understand what is happening. I am not programmatically setting the value, I am just typing into it the editor. Every time I press a key, the entire text is selected. Then, when I press another key, the entire text is replaced with the single character from the second key. This is surely not the intended behaviour of the editor! This is what is fixed by the change. Anyway, I was just experimenting with web components in Elm, I will probably not continue with ace-editor because I have no control over the editor when used as a web-component in Elm. It was all I could do to get text-in and text-out when it changes. There is no way that I can see to get the "editor object" and call the methods on it from Elm. Anyway, thanks so much for your reply -- keep up the good work.

On Fri, Mar 31, 2017 at 7:07 PM, Tomek Wytrębowicz <[email protected]

wrote:

Thanks for reportin :) I think it's not related to Elm, it happens in lots of our use cases.

However, I'm not sure whether it's a bug or a feature ;), as this is the default behavior of Ace editor. Simply juicyAceEditor.value = 'smth' <=> aceEditor.setValue('smth'). If you want to achieve non-default behavior you can always do as you mentioned:|

juicyAceEditor.editor.setValue( val, 1 );

For sure it's worth mentioning in README. I'll try to get some closer look to the latest Ace API, maybe I'd find something cleaner.

Any other comments are more than welcome :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Juicy/juicy-ace-editor/issues/24#issuecomment-290855824, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUTNq0rje0DZRiUmLG00e3UmU7kxxjMks5rrYc4gaJpZM4MwK-P .

-- Nick Perkins

nickperkinslondon avatar Apr 01 '17 17:04 nickperkinslondon

I'm running into this same issue, though I am using lit-html. I imagine the problem is coming from the way both Elm and lit-html are handling the dom. We might both be setting the value property every time there is a change to the editor. Anyway, this is a large issue for me as well. I'm using lit-html, setting the value property of the editor on each change to the contents of the editor, I'm seeing all sorts of strange behavior from the editor, it is very broken

lastmjs avatar May 01 '18 22:05 lastmjs

Maybe try add a setter to the value property?

Object.defineProperty(yourEditor, 'value', {
	set(val) { yourEditor.setValue(val, 1) }
});

alshakero avatar May 03 '18 09:05 alshakero