How prevent the tab key from exiting the Text Area component

조회 수: 20 (최근 30일)
Antony
Antony 2024년 1월 24일
댓글: dpb 2024년 1월 27일
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.

채택된 답변

dpb
dpb 2024년 1월 24일
이동: dpb 2024년 1월 24일
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
Antony
Antony 2024년 1월 27일
편집: Antony 2024년 1월 27일
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 2024년 1월 27일
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...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by