Repository navigation
[proposal][desktop] Tab character (\t) should be displayed as indentation in TextField #77512
Description
Tab Character \t should be displayed as indentation in EditableText, TextField and all implementations of Text widgets in Desktop
This is a common behaviour in many desktop applications
Flutter Channel: master
Platform: Desktop, Linux
Version: 2.1.0-11.0.pre.138
When Tab key is pressed while the TextField is focused, in a Flutter Desktop Application, by default, the focused TextField is unfocused and the focus shifts to another widget. That is a problem in my case as I want the user to be able to enter tab characters. But I partially solved it by using a RawKeyboardListener to detect when the user presses Tab key, and then inserted a \t to the TextField at the current cursor position through its controller.
The problem is that, the \t character is displayed as a small space, almost half as wide as whitespace, which is counterproductive.
There should be an option to configure how \t is displayed, as it can be of multiple number of spaces' width, and it should be customisable.
I believe this is not exactly a bug. For mobile devices, the Tab key is irrelevant. For web, pressing Tab key is helpful in shifting focus between UI elements.
But for desktop, it makes sense to have an option to customise how a Tab character is displayed in a TextField.
Suggestion
Add an option to disable focus shifting on Tab press on Desktop and add Tab character to the TextField. Provide a way to customise Tab character display, by equating it to a specific number of whitespaces that can be changed if required.
Activity
pedromassangocode commentedon Mar 8, 2021
Yes this is definitely a proposal. Just tested on Slack MacOS app and Tab button move focus to another component.
[-]\t Tab character display in TextField[/-][+][proposal][desktop] Tab character (\t) to add spaces in TextField[/+]TimWhiting commentedon Mar 11, 2021
Found a way to accomplish this:
But I agree that there should be two properties on
EditableTextandTextFieldcalled something like:bool acceptTabsint tabIndentationAnd TextField or Editable text should handle wrapping in the
Action/Shortcutswidget.code sample
aldrinmathew commentedon Mar 11, 2021
@TimWhiting @pedromassangocode
I tested the implementation by Tim Whiting and it works well. 👍
However, I reviewed the code and found that it is adding the appropriate number of spaces whenever the user presses Tab key. I have already implemented this in the application that I am developing. Is there anyway that we can add the '\t' character in the text and make it look like multiple spaces? I mean, without replacing the tab with spaces?
In theory, we should be able to configure and customise the display of certain characters in the text field. Especially when we consider the possibility that desktop applications developed by flutter might not always be mere "applications", they might be complex enough to be called "software".
Use case
I want the user to be able to add the raw tab character (\t) to the text field. And I want to customise the display of the tab character to resemble the equivalent number of spaces chosen by the user.
I am developing a text/code editor. I think you get where I am going with this. If a user/programmer presses tab to indent their content/code, and if I write code to replace the indentation with actual whitespace, someone's definitely getting angry. I can easily provide them with an option to replace '\t' with spaces, but that shouldn't be the default behaviour in this case.
[-][proposal][desktop] Tab character (\t) to add spaces in TextField[/-][+][proposal][desktop] Tab character (\t) should be displayed as indentation in TextField[/+]aldrinmathew commentedon Mar 11, 2021
@TimWhiting
This is the modified code. This won't run as there is no property called indentSpaceCount for TextField.
code sample
TimWhiting commentedon Mar 11, 2021
Yeah, I agree, the properties should be more like:
As a design note, for accessibility there needs to be a way to unfocus the field that accepts tabs to a larger focus scope to allow moving to a different field. I believe this is typically done by the escape key, but I could be wrong.
aldrinmathew commentedon Mar 11, 2021
@TimWhiting
Exactly, this model looks perfect. And yes, Escape key is usually the way to do it.
17 remaining items
justinmc commentedon Jul 26, 2021
Sorry I thought I had already replied here. I will see if I can get this in as part of my current text editing work. Thanks for the great design doc and good luck on your thesis!
flutter-triage-bot commentedon Jun 7, 2024
The
triaged-desktoplabel is irrelevant if there is noteam-desktoplabel orfyi-desktoplabel.