Page MenuHomePhabricator

Insert tabs and not spaces in indented blocks in CodeMirror
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

image.png (1,633×287 px, 23 KB)

What should have happened instead?:
CodeMirror 5/6 should indent with tab symbols, not spaces. This is especially needed if we someday replace CodeEditor with CodeMirror (as we should).

Details

Related Changes in Gerrit:

Event Timeline

Restricted Application added subscribers: Base, Aklapper. · View Herald Transcript

Are you requesting automatic indentation detection or literally tabs?

Whatever is easier to implement in CodeMirror (I assume it is just a config option). Currently it inserts spaces even where tabs are used. Tabs are preferable as a default for accessibility reasons:
https://adamtuttle.codes/blog/2021/tabs-vs-spaces-its-an-accessibility-issue/

Automatic indentation detection is not yet available from CodeMirror, and the indentUnit config has to be consistent throughout one document. Therefore, if we prescribe one tab as the default, then the editor will always indent with tabs even where spaces are used. One possible solution is to add this config to the future preferences panel (T359498) so that the user can choose appropriate indentUnit.

TemplateData uses tabs exclusively, as does CodeEditor, and I don’t think there are that many other instances where such spacing is present in wikitext pages. indentString doc seems to suggest that if you set indentUnit to \t and there isn’t sufficient space (not 4 spaces) to form a tab, it would be using spaces. Config solution is fine for the future, but CodeMirror still should use tabs by default given its current scope.

It's far from being done, but I think ideal solution is T357480. When that's implemented, templatedata can be registered to CodeMirror as a tag that contains JSON, and then you'd get the expected behaviour.

For the short-term, it sounds like we should add a preference (T359498) to dictate what Tab does: insert \t, or move focus to the next element in the tab order (the edit summary field). We can make the \t configurable too if we want, but I agree with stjn that \t should be the default.

Change #1100047 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] CodeMirror: indent with `\t`

https://gerrit.wikimedia.org/r/1100047

Change #1100047 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirror: indent with `\t`

https://gerrit.wikimedia.org/r/1100047

MusikAnimal assigned this task to Bhsd.
MusikAnimal moved this task from Improvement to Done on the MediaWiki-extensions-CodeMirror board.

It sounds like automatic indentation detection is a potential follow-up. Personally I think a preference is overkill… but I will note that eventually the preferences panel will probably be a dialog, giving more room for niche preferences like this if we want them. At any rate, let's save all of that for a different task.