Skip to content
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

Single line mode #2009

Open
beikov opened this issue Jun 16, 2020 · 4 comments
Open

Single line mode #2009

beikov opened this issue Jun 16, 2020 · 4 comments
Labels
editor-api feature-request Request for new features or functionality

Comments

@beikov
Copy link

beikov commented Jun 16, 2020

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?

@beikov
Copy link
Author

beikov commented Jun 16, 2020

Just found out that the padding on the right can be removed with scrollBeyondLastColumn: 0

@beikov
Copy link
Author

beikov commented Jun 16, 2020

It seems the following options remove all padding:

                wordWrap: 'off',
                lineNumbers: 'off',
                lineNumbersMinChars: 0,
                overviewRulerLanes: 0,
                overviewRulerBorder: false,
                lineDecorationsWidth: 0,
                hideCursorInOverviewRuler: true,
                glyphMargin: false,
                folding: false,
                scrollBeyondLastColumn: 0,
                scrollbar: {horizontal: 'hidden', vertical: 'hidden'},
                find: {addExtraSpaceOnTop: false, autoFindInSelection: 'never', seedSearchStringFromSelection: false},
                minimap: {enabled: false},

@alexdima alexdima added editor-api feature-request Request for new features or functionality labels Sep 18, 2020
@vikyd
Copy link

vikyd commented Feb 25, 2021

A vue componet vue-monaco-singleline: https://github.com/vikyd/vue-monaco-singleline

  • single line options
  • placeholder support

Demo: https://vikyd.github.io/vue-monaco-singleline-custom-language/

@djgrant
Copy link

djgrant commented Apr 28, 2022

For anyone here looking for a simple expression editor, I wrote https://github.com/djgrant/react-code-input, which turns <input /> elements into a mini code editor, and would welcome further contributions. Example https://code-input.vercel.app/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-api feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants