microsoft / microsoft/monaco-editor

Single line mode

Open
#2,009 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

editor-api feature-request
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:

grafik

Any idea how to remove that padding?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.