Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 51fb118

Browse files
committed
feat(plugins/plugin-client-common): be smarter about enabling line numbers in monaco-editor
right now, for SimpleEditor, we never use line numbers. but they can be quite helpful. this PR enables them, except for single-liners. also, we weren't distinguishing the coloring of the line numbers by selected line. monaco does this by default, we just weren't theme-aligning it well.
1 parent 42bef3d commit 51fb118

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

plugins/plugin-bash-like/src/test/bash-like/head.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ const rootRelative = (dir: string) => join(ROOT, dir)
2929
CLI.command(`${head} ${rootRelative('package.json')}`, this.app)
3030
.then(ReplExpect.ok)
3131
.then(SidecarExpect.open)
32-
.then(res =>
33-
this.app.client.waitUntil(async () => {
32+
.then(res => {
33+
let idx = 0
34+
return this.app.client.waitUntil(async () => {
3435
const linesNumbers = await this.app.client.$$(
3536
Selectors.SIDECAR_CUSTOM_CONTENT_LINE_NUMBERS(res.count, res.splitIndex)
3637
)
38+
if (++idx > 5) {
39+
console.error(`Still waiting for lineNumbers actual=${linesNumbers.length} expected=10`)
40+
}
3741
return linesNumbers.length === 10
3842
})
39-
)
43+
})
4044
.catch(Common.oops(this)))
4145

4246
it(`should ${head} -n 5 package.json and see 5 lines`, () =>

plugins/plugin-client-common/src/components/Content/Editor/SimpleEditor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ export default class SimpleEditor extends React.Component<Props, State> {
150150
private initMonaco(props: Props, state: State) {
151151
const cleaners = []
152152

153+
const nLines = props.content.split(/\n/).length
154+
153155
try {
154156
// here we instantiate an editor widget
155157
const providedOptions = {
@@ -162,7 +164,15 @@ export default class SimpleEditor extends React.Component<Props, State> {
162164
}
163165
const overrides: Monaco.IStandaloneEditorConstructionOptions = { theme: props.light ? 'vs' : 'vs-dark' }
164166
const options: Monaco.IStandaloneEditorConstructionOptions = Object.assign(
165-
defaultMonacoOptions(providedOptions),
167+
defaultMonacoOptions(
168+
Object.assign(
169+
{
170+
showLineNumbers: nLines > 1,
171+
lineNumbersMinChars: nLines.toString().length
172+
},
173+
providedOptions
174+
)
175+
),
166176
providedOptions,
167177
overrides
168178
)

plugins/plugin-client-common/src/components/Content/Editor/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export default class Editor extends React.PureComponent<Props, State> {
355355
// here we instantiate an editor widget
356356
const providedOptions = {
357357
value: '',
358+
showLineNumbers: true,
358359
readOnly: Editor.isReadOnly(props, state),
359360
language:
360361
state.content.contentType === 'text/plain'

plugins/plugin-client-common/src/components/Content/Editor/lib/defaults.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface Options extends editor.IEditorConstructionOptions {
2222
simple?: boolean
2323
fontSize?: number
2424
language?: string
25+
showLineNumbers?: boolean
2526
}
2627

2728
/** Once we scroll to the bottom or top, then start scrolling the enclosing scroll region */
@@ -59,10 +60,10 @@ export default (options: Options): editor.IEditorConstructionOptions => ({
5960
// simplify the UI?
6061
links: !options.simple,
6162
folding: !options.simple || !/markdown|text|shell/i.test(options.language),
62-
lineNumbers: options.simple ? 'off' : 'on',
63+
lineNumbers: !options.showLineNumbers ? 'off' : 'on',
6364
wordWrap: options.wordWrap || (options.simple ? 'off' : 'on'),
64-
wrappingIndent: 'indent',
6565
renderLineHighlight: options.simple ? 'none' : undefined,
6666
renderFinalNewline: !options.simple,
67-
lineDecorationsWidth: options.simple ? 0 : undefined
67+
lineDecorationsWidth: !options.showLineNumbers ? 0 : undefined,
68+
lineNumbersMinChars: options.lineNumbersMinChars || (!options.showLineNumbers ? 0 : undefined)
6869
})

plugins/plugin-client-common/web/scss/components/Editor/theme-alignment.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ body[kui-theme-style] .monaco-editor {
1717

1818
body[kui-theme-style] .monaco-editor .current-line ~ .line-numbers {
1919
transition: color 300ms ease-in-out;
20-
color: var(--color-brand-02);
20+
color: var(--color-text-02);
2121
}
2222
body[kui-theme-style] .monaco-editor .line-numbers {
2323
transition: color 300ms ease-in-out;
24-
color: var(--color-text-02);
24+
color: var(--color-base04);
2525
font-weight: 300;
2626
}
2727

0 commit comments

Comments
 (0)