Clear Filters
Clear Filters

How prevent the tab key from exiting the Text Area component

15 views (last 30 days)
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.

Accepted Answer

dpb on 24 Jan 2024
Moved: dpb on 24 Jan 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.
Antony on 27 Jan 2024
Edited: Antony on 27 Jan 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 on 27 Jan 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...

Sign in to comment.

More Answers (0)


Find more on Environment and Settings in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!