How prevent the tab key from exiting the Text Area component

20 visualizzazioni (ultimi 30 giorni)
Problem: The tab key changes the focus of the Text Area ui component, when running app designer apps.
I want to have a multi line text editor (Text Area) that inserts the tab character into the text I'm editing, like a programmers editor.
Is there some way to disable this behavior.

Risposta accettata

dpb
dpb il 24 Gen 2024
Spostato: dpb il 24 Gen 2024
Using the uitextarea <callback function> would be the only way, but I don't think you will be able to make it work for the <\t> character; it is treated especially to change focus of the control as you are awared. On top of this, to do it with the ValueChangingFcn callback, be aware of the following Note:
"Avoid updating the Value property of the TextArea object from within its own ValueChangingFcn callback, as this might result in unexpected behavior. To update the text area value in response to user input, use a ValueChangedFcn callback instead."
It would seem you would have to not only trap the character but if it were a tab, then reset focus back and then where is the user cursor on entry, etc., etc., etc., ...
Hence, while I doubt if even this would work well, the only way I see one might be able to do it would be to keep a running position counter and then insert tabs in the object when the user exits...
My guess this is simply not going to be feasible; you would need a custom-written UI component methinkks.
  2 Commenti
Antony
Antony il 27 Gen 2024
Modificato: Antony il 27 Gen 2024
Thanks for the advice, I agree with you, I believe that app designer catches the tab key and there's no way around that at lease with the built-in TextArea widget. This is of course a huge floor in app designer, that will prevent almost all source code editing tools being developed in App Designer.
Mathworks should really address this problem!
In the end I did manage to get around the problem by using the HTML ui widget, then embedding a local JS editor (ACE) into the HTML page. Works like a charm and as does most of the Matlab interfacing with JS.
dpb
dpb il 27 Gen 2024
Well, I for one had never thought of trying to build a code editor in App Designer.
I don't know how big a demand there might be, but if you see it and think it is a need, give the example use case and submit an official enhancement request.
It would seem something such as your workaround would be the logical way anyway, rewriting yet another code editor instead of linking to an existing one seems like a lot of effort and reinventing the wheel...

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by