microsoft / microsoft/monaco-editor
Single line mode
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Getting a single line-mode to work is not as straightforward as I thought. It would be nice if this could be added as a configuration option. Here is what worked for me:
editor.onKeyDown(e => {
if (e.keyCode == monaco.KeyCode.Enter) {
// We only prevent enter when the suggest model is not active
if (editor.getContribution('editor.contrib.suggestController').model.state == 0) {
e.preventDefault();
}
}
});
editor.onDidPaste(e => {
if (e.range.endLineNumber > 1) {
let newContent = "";
let lineCount = textModel.getLineCount();
for (let i = 0; i < lineCount; i++) {
newContent += textModel.getLineContent(i + 1);
}
textModel.setValue(newContent);
}
});
with the following editor options:
wordWrap: 'off',
lineNumbers: 'off',
lineDecorationsWidth: 0,
overviewRulerLanes: 0,
overviewRulerBorder: false,
scrollbar: { horizontal: 'hidden', vertical: 'hidden' },
But I'm still having problems with removing some of the padding on the left and right side of the editor:

Any idea how to remove that padding?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the editor configuration options and the keydown and paste handlers shown in the issue. Check how single-line behavior, suggestion handling, and editor padding are currently controlled. Done means a configuration option provides single-line mode, prevents unwanted newlines and pasted line breaks, and removes the remaining horizontal padding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100