-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ui.EDITOR_EOL, default to saving files with LF again #28119
Conversation
@@ -34,6 +34,7 @@ var UI = struct { | |||
SearchRepoDescription bool | |||
OnlyShowRelevantRepos bool | |||
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"` | |||
EditorEol string `ini:"EDITOR_EOL"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this ini
tag here is unnecessary because thiscase conversation is done implicitely, but I do like this expliciteness so that the name stays greppable.
By the way, where does this case conversation happen? It's not from the ini package, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the correct Go name would even be EditorEOL
I do not think this is right. See the discussion #27141 (comment) Even if you set I believe the best choice is to revert #27141 at the moment, make 1.21 users happy. At least, "\n" is more widely used but "\r\n" causes problems in POSIX. |
If that's because of textarea behaviour, we can fix this by setting the textarea value. |
Added the previous server-side eol convertion back, but it now respects the new setting of LF vs. CRLF too: e58dcc0 |
I guess the only thing missing here is to respect editorconfig on server-side as well, but for all intends, this will restore the previous replacement to LF that was done server-side. |
8806cc5
to
2dfcfe0
Compare
Done as well in 2dfcfe0, now the server also respects the editorconfig for this replacement. I guess it's still good to retain the client-side stuff so that copy out of monaco copies with the correct line endings. |
|
@@ -34,6 +34,7 @@ var UI = struct { | |||
SearchRepoDescription bool | |||
OnlyShowRelevantRepos bool | |||
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"` | |||
EditorEol string `ini:"EDITOR_EOL"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the correct Go name would even be EditorEOL
@@ -149,6 +149,9 @@ func NewFuncMap() template.FuncMap { | |||
"MermaidMaxSourceCharacters": func() int { | |||
return setting.MermaidMaxSourceCharacters | |||
}, | |||
"EditorEol": func() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
@@ -149,6 +149,9 @@ func NewFuncMap() template.FuncMap { | |||
"MermaidMaxSourceCharacters": func() int { | |||
return setting.MermaidMaxSourceCharacters | |||
}, | |||
"EditorEol": func() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
|
||
// convert all newlines in string to \n | ||
func ToLF(str string) string { | ||
return strings.ReplaceAll(str, "\r", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return strings.ReplaceAll(str, "\r", "") | |
return strings.ReplaceAll(str, "\r\n", "\n") |
|
||
// convert all newlines in string to \r\n | ||
func ToCRLF(str string) string { | ||
return strings.ReplaceAll(ToLF(str), "\n", "\r\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return strings.ReplaceAll(ToLF(str), "\n", "\r\n") | |
return strings.ReplaceAll(str, "(?:[^\r])\n", "\r\n") |
@@ -45,3 +45,11 @@ func TestToSnakeCase(t *testing.T) { | |||
assert.Equal(t, expected, ToSnakeCase(input)) | |||
} | |||
} | |||
|
|||
func TestToLF(t *testing.T) { | |||
assert.Equal(t, "\na\nbc\n\n", ToLF("\r\na\r\nb\rc\n\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Equal(t, "\na\nbc\n\n", ToLF("\r\na\r\nb\rc\n\n")) | |
assert.Equal(t, "\r\na\nbc\n\n", ToLF("\r\r\na\r\nb\rc\n\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or how do we want to handle this case?
I can live both with the current approach of removing it completely, and my proposed approach of only converting \r\n -> \n
The same problem as BOM: #28935 (comment)
|
Yes, like with BOM we should just round-trip the file unmodified. The only problem is new files and files with equal amount of CRLF and LF, for those we need to bias towards one format, which could come from editorconfig with fallback to global server config. I think the approach here is not correct and we should actually avoid backend convertion completely. So I think it's better to make a new PR, maybe I will have a look later, but feel free to raise something @wxiaoguang. |
IMO at the moment, backend convertion can't be avoided. Because HTML textarea always passes "\r\n" to backend, it is the standard. |
Yeah, but we can at least avoid altering the content until the point where it reaches the editor. Maybe it's ideal to use a |
Fixes: #28097
Replaces: #28101
Assuming we consider it a bug that people on Windows get CRLF endings without a editorconfig, we should backport this to 1.21.