How prevent the tab key from exiting the Text Area component
20 views (last 30 days)
Show older comments
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.
0 Comments
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.
2 Comments
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...
More Answers (0)
See Also
Categories
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!