-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
fix: Remove extra whitespace in the untitled editor label #108039
Conversation
Some Updates:
|
Is there any issue happened in pipline of test? It seems like it cannot process normally. @bpasero |
@@ -93,7 +93,9 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt | |||
// we have no associated file path. In that case we | |||
// prefer the file name as title. | |||
if (this.configuredLabelFormat === 'content' && !this.hasAssociatedFilePath && this.cachedModelFirstLineWords) { | |||
return this.cachedModelFirstLineWords; | |||
// Normalize multiple whitespaces to a single whitespace for the untitled editor label | |||
const normalizedFirstLineWords = this.cachedModelFirstLineWords ? this.cachedModelFirstLineWords.replace(/\s+/g, ' ') : ''; |
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.
Why is this not done at the point where we cache the name?
vscode/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts
Lines 369 to 372 in 50d9f05
this._onDidChangeName.fire(); | |
} | |
} | |
} |
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.
Update: Normalized when cached the first line words.
@@ -365,7 +365,8 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt | |||
} | |||
|
|||
if (modelFirstWordsCandidate !== this.cachedModelFirstLineWords) { | |||
this.cachedModelFirstLineWords = modelFirstWordsCandidate; | |||
// Normalize multiple whitespaces to a single whitespace for the untitled editor label | |||
this.cachedModelFirstLineWords = modelFirstWordsCandidate ? modelFirstWordsCandidate.replace(/\s+/g, ' ') : ''; |
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 would put this after the .trim()
call here:
const firstLineText = this.textEditorModel?.getValueInRange({ startLineNumber: 1, endLineNumber: 1, startColumn: 1, endColumn: UntitledTextEditorModel.FIRST_LINE_NAME_MAX_LENGTH + 1 }).trim(); |
Because then we do a good check modelFirstWordsCandidate !== this.cachedModelFirstLineWords
Thanks!
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.
Update: remove extra spaces after trim first line text.
Thanks! |
This PR fixes #107979
Normalize multiple whitespaces to a single whitespace for the untitled editor label:
Before:
After: