mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
Configure tab size when viewing a file #4353
Open
opened 2025-11-02 05:47:37 -06:00 by GiteaMirror
·
49 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1
v1.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v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
issue/confirmed
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#4353
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @markusamshove on GitHub (Nov 19, 2019).
Hi,
Is there an option to configure how many spaces a tab contains?
Our java files are indented with tabs and when I view them, every tab seems to be 8 spaces wide.
Normally I would expect 4 spaces for java, c# and similar languages
@silverwind commented on GitHub (Nov 19, 2019):
I think you can put a
.editorconfigin your repo and some aspects like the editor will honour it, not sure about repo viewer.@stale[bot] commented on GitHub (Jan 19, 2020):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
@stale[bot] commented on GitHub (Feb 2, 2020):
This issue has been automatically closed because of inactivity. You can re-open it if needed.
@KaKi87 commented on GitHub (May 24, 2020):
Hello,
How can I change Gitea's global tab size from 8 to 4 ?
Thanks.
@Spongman commented on GitHub (Jun 25, 2020):
please reopen. (stalebot is bad project management)
does this mean that managing projects that use tabs is not supported on Gitea? it looks like
.editorconfigis used when editing files, but ignored when viewing them.workaround: add
custom/templates/custom/header.tmpl:edit: added
-moz-tab-sizeafter @tmont, below.@stale[bot] commented on GitHub (Aug 31, 2020):
This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
@KaKi87 commented on GitHub (Aug 31, 2020):
up
@stale[bot] commented on GitHub (Oct 31, 2020):
This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
@KaKi87 commented on GitHub (Oct 31, 2020):
up
@Exagone313 commented on GitHub (Nov 15, 2020):
I build Gitea with this patch:
@tmont commented on GitHub (Dec 20, 2020):
I had to add this to @Spongman's custom template to get things working in Firefox as it does not (yet) support un-prefixed
tab-size:@vhscom commented on GitHub (Jan 19, 2022):
Here's a bookmarklet you can use to format the tab size for Gitea when viewing code in compare/diff view through the web interface.
Adjust to your liking. Alternative options are to (a) add an
.editorconfigfile to the repository as mentioned by @silverwind or (b) use a different diff viewer such as delta.@KaKi87 commented on GitHub (Jan 19, 2022):
Well, you'd better use a userstyle rather than a bookmarklet
@silverwind commented on GitHub (Jan 19, 2022):
I think this issue is still open because the code view doesn't respect the configured tab-size in
.editorconfig. The web editor itself certainly already does.@KaKi87 commented on GitHub (Jan 19, 2022):
Requiring such file doesn't seem right.
@silverwind commented on GitHub (Jan 19, 2022):
Yes, I think a user setting for default tab size is also desirable. But
.editorconfigshould have precedence when present.@markusamshove commented on GitHub (Jan 19, 2022):
I'd say:
User settings > editorconfig > highlighting lib > default
@danebou commented on GitHub (Feb 3, 2022):
Who the heck uses a tab size of 8 by default? lol. Really surprised this isn't fixed. In addition to this, the default tab size should be 4 since almost every IDE out of the box uses 4.
(Oh I guess this fight goes along with the Linux Kernel standards. Well since I doubt gitea is being used by the Linux Kernal peops, I still argue 4 is a good default)
@vhscom commented on GitHub (Feb 3, 2022):
One thing to take into consideration is that I doubt many projects do, or would even want, to add an
.editorconfigfile if they're using prettier. I could see that causing headaches if they're not in perfect alignment. Besides, who wants to add another dotfile to their repo. A sensible default of 4 spaces would be fine. But it would be even better to give the user control straight from the interface.@KaKi87 commented on GitHub (Feb 3, 2022):
Yes. Personally, I started using spaces as indentation character instead of tabs because of this issue. And this isn't right.
@silverwind commented on GitHub (Feb 4, 2022):
FWIW, browsers are dictated by spec to use default size 8 thought I do agree 4 is a generally better default.
@Crystal-RainSlide commented on GitHub (Jun 23, 2022):
If we add this (
?ts=4): https://github.com/tiimgreen/github-cheat-sheet#adjust-tab-spaceThen we can just make the links with the different tab size parameter as the "Change tab size" button, and we also got permalink for them. If someone figured out the right tab size for a file, then he can just share the permalink to others and save their time by a little bit.
With some tab-size-changing JavaScript and
history.pushState(), we can also save the navgation/reloading of the "Change tab size" link-buttons.@delvh commented on GitHub (Jun 23, 2022):
While I can definitely see why adding it as a query param would be useful, how would it handle the whitespace for files with differing behavior defined in the
editorconfig?Should the editorconfig simply be ignored globally when that parameter is set?
@silverwind commented on GitHub (Jun 24, 2022):
I think in general we want a setting UI where user can set their preference, similar to what GitHub now has for tab size:
https://github.com/settings/appearance
That setting should overrule
.editorconfig. Only through the special valuedefaultwould editorconfig then be applied.We can du the url param too, but I think it's too obscure of a feature in general to be useful.
@Crystal-RainSlide commented on GitHub (Jun 25, 2022):
On GitHub:
tsparameter >.editorconfig> tab size in the user settings. Everyone can check this by themselves.This seems to be decided by the scope.
tsparameter is specifc to a webpage,.editorconfigis specifc to a repo, and tab size in the user settings is specifc to everything a user sees, and the smaller the scope the higher the priority.Yes.
Obscure is what GitHub had done wrong, anyone else can get it right (GitHub itself included).
I'd already talked about the "Change tab size" button thing, but let's see if I can come up with some showcase...
Update: I'm trying to write a userscript to add a "Change tab size" button for both try.gitea.io and GitHub.
@Spongman commented on GitHub (Jun 28, 2022):
it should be simple for the user to easily, and permanently override whatever is in a repo's .editorconfig. the whole point of using tabs is that the indentation amount is configurable by the viewer, not baked into the source.
@UnlimitedCookies commented on GitHub (Sep 9, 2022):
Unfortunately, with this patch 4 spaces and 1 tab are not the same width 😨 .
@omenos commented on GitHub (Dec 4, 2022):
Both GitHub and GitLab have a user preference for defining the tabstop width for viewing files. As long as the
.editorconfigpreferences only apply to the editor view, it shouldn't be viewed as a solution here and other related issues.Tabstop size is important for languages that enforce tabs over spaces, such as Go. I'm currently using the Stylus extension to override tabstops for forge sites, including my self-hosted instance, but this is a browser specific workaround on my desktop; it does not apply to mobile where screen real estate is even more valuable.
I understand the addition of this feature is not completely simple, but it would be greatly appreciated!
@silverwind commented on GitHub (Dec 5, 2022):
I guess we can implement
2,4,8,autooptions. Default beingautowhich derives from editorconfig, and possibly falls back to a default of 4 (or 8, which is still what browsers default to, but I think it's antiquated and 4 is a better default).@arkadiuszmakarenko commented on GitHub (Feb 17, 2023):
This would be very welcomed change.
@eliliam commented on GitHub (Aug 24, 2023):
How's this coming? Six months ago @silverwind indicated the setting could be added, has anyone been able to work on this yet?
@Palid commented on GitHub (Jan 27, 2024):
@silverwind do you need help with someone taking this over? I'd gladly implement this change
@silverwind commented on GitHub (Mar 16, 2024):
Feel free to take a stab at implementing such a "indentation size" dropdown on top right side of file view which then would alter the CSS. The default option should be "auto", e.g. the current value that depends on
.editorconfigwith fallback to4. Ideally the option value should sync into backend as a user setting so it's remembered between browsing sessions.Personally I don't need this feature because I'm a strong proponent of
.editorconfig.@jclsn commented on GitHub (Jan 22, 2025):
Would like to see this too. Such basic feature!
@KaKi87 commented on GitHub (Jan 22, 2025):
Forgejo supports this btw
@omenos commented on GitHub (Jan 22, 2025):
Which part? Forgejo does default to a width of four characters for tabs, but as of Forgejo v10 I have not seen a user configurable tab size parameter available. I may have missed it, but there is a similar issue over on Forgejo about this same topic:
feat: tab size should be configurable #5672
@KaKi87 commented on GitHub (Jan 23, 2025):
Sorry for the ambiguity, I meant it supports
.editorconfig, which is the majority request here.@wxiaoguang commented on GitHub (Jan 23, 2025):
But forjoge ever largely copied Gitea's code, and new Gitea has many unique features that are not in forgejo.
For
editorconfigpart, there is no difference.@KaKi87 commented on GitHub (Jan 23, 2025):
Mea culpa, since users here requested for the file viewer to support
.editorconfigbut no one ever announced here this was implemented, I thought when seeing in that linked Forgejo issue someone saying it was implemented, that Forgejo maintainers did it. Sorry for the disturbance.So it's still good to know for the people here though, that now they can configure tab size per-repo with
.editorconfig.Have a nice week
@wxiaoguang commented on GitHub (Jan 23, 2025):
That code was also taken from Gitea.
For the author's question:
editorconfigis supported@omenos commented on GitHub (Jan 23, 2025):
As the idea was mentioned up in the Forgejo discussion, does Gitea supported rendering projects using nested
editorconfigsetups? I can see this as a useful feature for multi-language monorepos.@silverwind commented on GitHub (Jan 23, 2025):
I don't think a user setting is strictly needed as the ideal tab size can differ based on file. One file might render better with 4, another one with 8.
I think we could simply add
<select>elements to the file view and code editor that changes the tab size only on the current page, not remembering anything.@wxiaoguang commented on GitHub (Jan 23, 2025):
I think no at the moment.
It's not difficult to support this feature, the only concern is that it might slow down some pages slightly because it needs to check every parent dir to detect
editorconfigand apply.So IMO the issue looks like this at the moment:
editorconfigin mono-repo (many users need it):@silverwind commented on GitHub (Jan 23, 2025):
I'm not sure how the editorconfig module does it, but ideally this is a O(n) operation, n being the number of parent directories of the viewed file.
@silverwind commented on GitHub (Jan 27, 2025):
I will look into adding these
<select>boxes soon to file view and code editor.@adamel commented on GitHub (Mar 25, 2025):
Personally I would very much have the ability to configure a global .editorconfig config in Gitea to use for all repositories that does not have one.
We have different indent settings for different languages, but all repositories use the same styles, so adding a .editorconfig file to each of several hundred repositories does not really make sense.
@silverwind commented on GitHub (Mar 25, 2025):
Makes sense to have such a file, but it may become challenging to merge multiple
.editorconfigfiles, maybe https://github.com/editorconfig/editorconfig-core-go has some support.Edit: It may support multiple files already, but I think we'd have shift the
root=truestatement to the new "root file" so thateditorconfig-core-godoes not stop at the repo root file.@adamel commented on GitHub (Mar 25, 2025):
For us there is no need to merge multiple files - if there is a file in the repository use only that, otherwise use only the globally configured file from Gitea as a fallback.
@silverwind commented on GitHub (Mar 25, 2025):
Right, could just take the global file as a "fallback".