Skip to content

Commit 9fc2a7a

Browse files
authored
Improve rendering of no file system provider when remote connection isn't available (fix microsoft#198764) (microsoft#199553)
* Improve rendering of no file system provider when remote connection isn't available (fix microsoft#198764) * .
1 parent bc90807 commit 9fc2a7a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/vs/base/common/strings.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ export function truncate(value: string, maxLength: number, suffix = '…'): stri
9292
return `${value.substr(0, maxLength)}${suffix}`;
9393
}
9494

95+
export function truncateMiddle(value: string, maxLength: number, suffix = '…'): string {
96+
if (value.length <= maxLength) {
97+
return value;
98+
}
99+
100+
const prefixLength = Math.ceil(maxLength / 2) - suffix.length / 2;
101+
const suffixLength = Math.floor(maxLength / 2) - suffix.length / 2;
102+
103+
return `${value.substr(0, prefixLength)}${suffix}${value.substr(value.length - suffixLength)}`;
104+
}
105+
95106
/**
96107
* Removes all occurrences of needle from the beginning and end of haystack.
97108
* @param haystack string to trim

src/vs/base/test/common/strings.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ suite('Strings', () => {
371371
assert.strictEqual('hello…', strings.truncate('hello world', 5));
372372
});
373373

374+
test('truncateMiddle', () => {
375+
assert.strictEqual('hello world', strings.truncateMiddle('hello world', 100));
376+
assert.strictEqual('he…ld', strings.truncateMiddle('hello world', 5));
377+
});
378+
374379
test('replaceAsync', async () => {
375380
let i = 0;
376381
assert.strictEqual(await strings.replaceAsync('abcabcabcabc', /b(.)/g, async (match, after) => {

src/vs/workbench/browser/parts/editor/editorPlaceholder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import 'vs/css!./media/editorplaceholder';
77
import { localize } from 'vs/nls';
8+
import { truncate, truncateMiddle } from 'vs/base/common/strings';
89
import Severity from 'vs/base/common/severity';
910
import { IEditorOpenContext, isEditorOpenError } from 'vs/workbench/common/editor';
1011
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -28,7 +29,6 @@ import { SimpleIconLabel } from 'vs/base/browser/ui/iconLabel/simpleIconLabel';
2829
import { FileChangeType, FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
2930
import { toErrorMessage } from 'vs/base/common/errorMessage';
3031
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
31-
import { truncate } from 'vs/base/common/strings';
3232

3333
export interface IEditorPlaceholderContents {
3434
icon: string;
@@ -47,7 +47,7 @@ export interface IErrorEditorPlaceholderOptions extends IEditorOptions {
4747

4848
export abstract class EditorPlaceholder extends EditorPane {
4949

50-
private static readonly PLACEHOLDER_LABEL_MAX_LENGTH = 1024;
50+
protected static readonly PLACEHOLDER_LABEL_MAX_LENGTH = 1024;
5151

5252
private container: HTMLElement | undefined;
5353
private scrollbar: DomScrollableElement | undefined;
@@ -245,7 +245,7 @@ export class ErrorPlaceholderEditor extends EditorPlaceholder {
245245
} else if (isEditorOpenError(error) && error.forceMessage) {
246246
label = error.message;
247247
} else if (error) {
248-
label = localize('unknownErrorEditorTextWithError', "The editor could not be opened due to an unexpected error: {0}", toErrorMessage(error));
248+
label = localize('unknownErrorEditorTextWithError', "The editor could not be opened due to an unexpected error: {0}", truncateMiddle(toErrorMessage(error), EditorPlaceholder.PLACEHOLDER_LABEL_MAX_LENGTH / 2));
249249
} else {
250250
label = localize('unknownErrorEditorTextWithoutError', "The editor could not be opened due to an unexpected error.");
251251
}

0 commit comments

Comments
 (0)