Giter VIP home page Giter VIP logo

react-simple-code-editor's Introduction

react-simple-code-editor

Build Status MIT License Version Bundle size (minified + gzip)

Simple no-frills code editor with syntax highlighting.

Why

Several browser based code editors such as Ace, CodeMirror, Monaco etc. provide the ability to embed a full-featured code editor in your web page. However, if you just need a simple editor with syntax highlighting without any of the extra features, they can be overkill as they don't usually have a small bundle size footprint. This library aims to provide a simple code editor with syntax highlighting support without any of the extra features, perfect for simple embeds and forms where users can submit code.

Features

  • Modular syntax highlighting with third party library
  • Indent line or selected text by pressing tab key, with customizable indentation
  • Automatic indent on new lines
  • Wrap selected text in parens, brackets, or quotes
  • Undo whole words instead of letter by letter
  • Accessible, use Ctrl+Shift+M (Mac) / Ctrl+M to toggle capturing tab key

Installation

npm install react-simple-code-editor

or

yarn add react-simple-code-editor

Usage

You need to use the editor with a third party library which provides syntax highlighting. For example, it'll look like following with prismjs:

import React from 'react';
import Editor from 'react-simple-code-editor';
import { highlight, languages } from 'prismjs/components/prism-core';
import 'prismjs/components/prism-clike';
import 'prismjs/components/prism-javascript';
import 'prismjs/themes/prism.css'; //Example style, you can use another

function App() {
  const [code, setCode] = React.useState(
    `function add(a, b) {\n  return a + b;\n}`
  );
  return (
    <Editor
      value={code}
      onValueChange={code => setCode(code)}
      highlight={code => highlight(code, languages.js)}
      padding={10}
      style={{
        fontFamily: '"Fira code", "Fira Mono", monospace',
        fontSize: 12,
      }}
    />
  );
}

Note that depending on your syntax highlighter, you might have to include additional CSS for syntax highlighting to work.

Props

The editor accepts all the props accepted by textarea. In addition, you can pass the following props:

  • value (string): Current value of the editor i.e. the code to display. This must be a controlled prop.
  • onValueChange (string => mixed): Callback which is called when the value of the editor changes. You'll need to update the value prop when this is called.
  • highlight (string => string | React.Node): Callback which will receive text to highlight. You'll need to return an HTML string or a React element with syntax highlighting using a library such as prismjs.
  • tabSize (number): The number of characters to insert when pressing tab key. For example, for 4 space indentation, tabSize will be 4 and insertSpaces will be true. Default: 2.
  • insertSpaces (boolean): Whether to use spaces for indentation. Default: true. If you set it to false, you might also want to set tabSize to 1.
  • ignoreTabKey (boolean): Whether the editor should ignore tab key presses so that keyboard users can tab past the editor. Users can toggle this behaviour using Ctrl+Shift+M (Mac) / Ctrl+M manually when this is false. Default: false.
  • padding (number): Optional padding for code. Default: 0.
  • textareaId (string): An ID for the underlying textarea, can be useful for setting a label.
  • textareaClassName (string): A className for the underlying textarea, can be useful for more precise control of its styles.
  • preClassName (string): A className for the underlying pre, can be useful for more precise control of its styles.

Demo

react-simple-code-editor.github.io/react-simple-code-editor

How it works

It works by overlaying a syntax highlighted <pre> block over a <textarea>. When you type, select, copy text etc., you interact with the underlying <textarea>, so the experience feels native. This is a very simple approach compared to other editors which re-implement the behaviour.

The syntax highlighting can be done by any third party library as long as it returns HTML and is fully controllable by the user.

The vanilla <textarea> doesn't support inserting tab characters for indentation, so we re-implement it by listening to keydown events and programmatically updating the text. One caveat with programmatically updating the text is that we lose the undo stack, so we need to maintain our own undo stack. As a result, we can also implement improved undo behaviour such as undoing whole words similar to editors like VSCode.

Limitations

Due to the way it works, it has certain limitations:

  • The syntax highlighted code cannot have different font family, font weight, font style, line height etc. for its content. Since the editor works by aligning the highlighted code over a <textarea>, changing anything that affects the layout can misalign it.
  • The custom undo stack is incompatible with undo/redo items browser's context menu. However, other full featured editors don't support browser's undo/redo menu items either.
  • The editor is not optimized for performance and large documents can affect the typing speed.
  • We hide text in the textarea using -webkit-text-fill-color: transparent, which works in all modern browsers (even non-webkit ones such as Firefox and Edge). On IE 10+, we use color: transparent which doesn't hide the cursor. Text may appear bolder in unsupported browsers.

Contributing

While developing, you can run the example app to test your changes:

yarn example

Make sure your code passes TypeScript and ESLint. Run the following to verify:

yarn typescript
yarn lint

To fix formatting errors, run the following:

yarn lint -- --fix

react-simple-code-editor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-simple-code-editor's Issues

css highlighting doesn't seem to work

Current behaviour

Text appears as unstyled textarea. However, when inspecting the DOM, grammar does appear to work since it creates a bunch of span elements with different classes corresponding to the grammar.

Expected behaviour

CSS to be highlighted

Code sample

import React, { useState } from 'react';
import Editor from 'react-simple-code-editor';
import { highlight, languages } from 'prismjs';
import 'prismjs/components/prism-css';

const CssEditor: React.FC = () => {
  const [value, setValue] = useState('');

  return <Editor
    value={value}
    onValueChange={setValue}
    highlight={(code) => highlight(code, languages.css, 'css')}
  />;
};

export default CssEditor;

Screenshots (if applicable)

image

What have you tried

Tried browsing the prism documentation and including different prism css files.

Your Environment

software version
typescript 3.7.5
react-simple-code-editor 0.11
react 16.12
npm or yarn 6.13.7
node 12.8.1
browser FDE

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Content in uneditable on scroll

Current behaviour - I have set a height of 500 px and overflowY to scroll. Still when I try to scroll down the content becomes uneditable. Only the initial 500px area is editable.

Expected behaviour - Ideally the entire text area should be editable. Also, I dont want to not freeze the height. If I set no height it automatically grows with content but thats not what I want. I would like to freeze the heght and view the remaining content on scrolling.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Uncaught Error: Objects are not valid as a React child

Current behaviour

After upgrading my Gatsby project dependencies, the editor won't render any text (get Uncaught Error: Objects are not valid as a React child). Everything was working great before. The only thing that doesn't cause a crash is an empty string as the value. As son as I set the value to something as simple as 'test' it crashes.

Expected behaviour

Uncaught Error: Objects are not valid as a React child (found: object with keys {type, value}). If you meant to render a collection of children, use an array instead. in pre (created by Editor) in div (created by Editor) in Editor (at test.tsx:18) in div (at test.tsx:17) in Test (created by HotExportedTest)

Code sample

import React, { useState } from 'react';

import Editor from 'react-simple-code-editor';
// @ts-ignore
import { highlight, languages } from 'prismjs/components/prism-core';

export const Test = () => {

const [text, setText] = useState('');

const onCodeChanged = (code: string) => {
setText(code);
}

return (
<div style={{border: '1px solid gray', height: 100}}>
<Editor
value={text}
onValueChange={code => onCodeChanged(code)}
highlight={code => highlight(code, languages.json)}
padding={10}
className="container__editor"
style={{
fontFamily: 'Menlo, Consolas, "Courier New", monospace',
fontSize: 13,
whiteSpace: 'pre'
}}
/>

)
}

export default Test;

Screenshots (if applicable)

What have you tried

Your Environment

software version
react-simple-code-editor 0.11.0
react 16.13.1
npm or yarn yarn 1.22.4
node 13.11.0
browser chrome

Consider enforcing overflow-wrap

Current behaviour

I have tested a long string (like mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm) at the demo — and it doesn't work due to the styles you're using there for the container.

Expected behaviour

In my opinion, both textarea and the <pre> for the code should have an overflow-wrap etc. enforced to a break-word as in some browsers other values cannot be set for a textarea, leading to the misalign of the visual representation of the code and the text itself.

Proposed solution.

This behaviour works from the box at the codesandbox, but as seen at the demo it is very easy to shoot yourself in the leg and enable the bad behaviour, so I think the values for white-space, word-break and overflow-wrap shouldn't be inherited, but should be set to the ones that work for most cases (white-space could have also different effects for regular elements and text inside textarea from what I remember).

Cursor get transparent!

Current behaviour

Cursor get trasparent,

Expected behaviour

Cursor shouldn't get transparent like you mentioned on your documentation

Code sample

I use code based on your documentation with code inside using your demo

Screenshots (if applicable)

image

What have you tried

I already tried using style={{selectionColor : '#000'}} to set cursor black, but it's not work

Your Environment

software version
react-simple-code-editor ^0.8.0
react ^16.7.0
npm or yarn 6.2.0
node 10.8.0
browser Google Chrome Version 72.0.3626.109

How do I use CSS prism themes?

Current behaviour

When I use vsc-dark-plus, I can make sure that all torkens have the proper color except for the background.

Expected behaviour

May this line be removed?

https://github.com/satya164/react-simple-code-editor/blob/73b57bf4d548257890f9ed0ee83ee37ec099b256/src/index.js#L625

Code sample

require('./prism-vsc-dark-plus.css')
export default function Editor(){
  return <SimpleEditor
				value={'<Button />'}
				highlight={highlight(isVueSFC ? 'html' : 'jsx')}
				// Padding should be passed via a prop (not CSS) for a proper
				// cursor position calculation
				padding={space[2]}
				// to make sure the css styles for prism are taken into account
				preClassName={'language-jsx'}
			/>
}

Screenshots (if applicable)

Capture d’écran 2020-02-16 à 6 40 23 PM

Sandbox

https://codesandbox.io/s/suspicious-flower-5rl8e

Your Environment

software version
react-simple-code-editor 0.11.0
react 16
npm or yarn yarn
node 11
browser Firefox & Chrome

[Bug] Cursor showing on the wrong letter on chrome

Current behaviour

I discovered it on my project but you can have it on the demo with chrome.
The cursor is printed on the wrong character. When you type a char, it is added at a position other than the cursor.

Expected behaviour

I would like my cursor on the right char.

Code sample

Try to copy paste this code on the demo and then enter a char at the end

import React from "react";
import ReactDOM from "react-dom";

function App() {
  return (
    <h1>Hello world</h1>
  );
}

ReactDOM.render(<App />, document.getElementById("root" 
  function ( test

Screenshots (if applicable)

Capture d’écran 2020-02-11 à 13 55 12

What have you tried

I try changing css attributes on class editor but didn't successfully fixed the issue

Your Environment

You can use the same as the one used by the demo but mine is:

software version
react-simple-code-editor 0.11.0
react 16.12.0
npm 6.13.4
node 10.15.3
browser chrome (mac OS) 80.0.3987.87

Scrolling works only on Highlighted texts

Current behaviour

I'm using react-simple-code-editor along with prism for highlighting.

when scrolling, only the highlighted parts are scrolled.
the scroll in not working when i type something but when I select all texts and scroll only the highlighted texts are scrolled and it overlaps the text.

Expected behaviour

I expect the Scroll to work smoothly and not to overlap contents.

Code sample

Component

<React.Fragment> <div> <Editor value={this.state.cssCode} onValueChange={this.onValueChange} highlight={cssCode => highlight(cssCode, languages.css)} padding={10} className="editor-container" tabSize={4} /> </div> </React.Fragment>

Style
.editor-container { border: 1px solid #dfe2e6; height: 100px; background-color: #fff; margin-bottom: 10px; padding: 10px 12px; border-radius: 6px; letter-spacing: 2px; overflow: auto; padding-right: 23px; width: calc(100% - 24px); margin-left: 8px; margin-right: 8px; }

Your Environment

software version
react-simple-code-editor 0.10.0
react 16.9.0
npm or yarn 1.21.1
node 12.13.0
browser Chrome

Expose onKeyDown

Greetings,

I'm looking to use the Editor in a dialog, and listen for cmd + enter to save some mouse movement. I tried adding a listener on keydown, which worked, but apparently blows away whatever important thing it was doing to save the value properly.

Is there anyway to get access to key events without interrupting normal operations? Or potentially add a counterpart to onValueChange that exposes raw keyboard events?

Noticed "_handleKeyDown" but wasn't able to tie into it.

Thanks!

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Cannot insert tab characters

Current behaviour

In an editor with prop insertSpaces={false} and tabSize={1}, pressing the tab key inserts 5 spaces.

Expected behaviour

In an editor with prop insertSpaces={false} and tabSize={1}, pressing the tab key should insert a tab character.

Possible cause

I think that this is because of an error on line 256 of index.js where 5 spaces are used instead of a literal tab character

const tabCharacter = (insertSpaces ? ' ' : '     ').repeat(tabSize);

Your Environment

For reference, I am using version 0.9.4 from npm.

I would be happy to submit a PR replacing the spaces with a tab character.

How to remove the thin blue border?

I'm sure I'm doing something wrong because the editor on your homepage has no borders.

Current behaviour

A thin blue border appears around the outside of the editor even when border is set to 0.

Expected behaviour

Border should follow the specified style and disappear.

Code sample

<Editor
        value={props.headers}
        onValueChange={code => props.onHeadersChange(code)}
        highlight={code => highlight(code, languages.js, "javascript")}
        padding={10}
        style={{
          fontFamily: '"Fira code", "Fira Mono", monospace',
          border: "0px",
          borderWidth: 0
        }}
      />

Screenshot

https://imgur.com/TQMnSTy

What have you tried

Different style overrides.

Your Environment

software version
react-simple-code-editor 0.10.0
prismjs 1.17.1
react 16.10.2
npm or yarn 6.9.0
node 10.16.3
browser chrome

Missing line number

Great work !

Only thing missing is line numbering.

Are you planning to add this feature ?

thanks

Line numbers

It would be nice to be able to add line numbers. I know there is a prismjs plugin for this but it doesnt work without being able to add a classname to the <pre>.

Undo via CMD+Z makes the cursor jump to the end of the text

Current behaviour

Undo via CMD+Z makes the cursor jump to the end of the text.

issue

☝️Focus on the cursor

Expected behaviour

Like normal textarea elements an undo action should move the cursor to the previous position.

normal

☝️Focus on the cursor

Code sample

For the react-simple-code-editor textarea: http://satya164.xyz/react-simple-code-editor/
For a plain-old textarea: https://flekschas.github.io/textbox/

What have you tried

  1. type in text
  2. hit CMD+Z

Your Environment

software version
react-simple-code-editor v0.9.10 and whatever runs on http://satya164.xyz/react-simple-code-editor/
react no idea, check http://satya164.xyz/react-simple-code-editor/
npm or yarn not used
node not used
browser Chrome v75

Server-side rendering?

Can you please clarify (in readme), is it meant to be compatible with server-side rendering?

Enable spellcheck for Editor's textarea

Current behaviour

spellcheck 's textarea attribute is set in false and there is no chance to enable it
https://github.com/satya164/react-simple-code-editor/blob/master/src/index.js#L579

Expected behaviour

It would be great to be able to set spellcheck 's textarea attribute either to true or false

Code sample

 <Editor spellCheck={true} />

Your Environment

software version
react-simple-code-editor 0.10.0
react 16.12.0
npm or yarn yarn 1.21.1
node v8.16.0
browser chrome

Thanks for the amazing editor!

Exposing "Reset Code" Function Outside Editor

I'm using react-live which leverages this project. The {CTRL|CMD}+Z functionality works as expected.

I was just wondering if a similar "reset code" function could be made callable from an external button onClick event, for example.

I want to reset back to the initial state of the code passed to the editor and have a button reset to this value on demand. The keyboard undo is good as-is, but this more general case (undo all) seems to be missing.

This would be valuable for code walk-throughs without having to refresh the entire page and lose context in a long scroll, etc.

I'm willing to work on a PR if there is consensus on the feature.

License?

I see various references to the MIT License, but the license itself is missing.

proposal: ability to set unequal padding to one side of the editor

Would be nice to be able to set padding on one side of the editor that is not equal to the other sides. For instance: padding: 0 0 0 32px

Right now it seems like the padding prop accepts a number or a string and applies that value to all sides of the editor: https://github.com/satya164/react-simple-code-editor/blob/360e41518930e8f51633172299a5e5efc91c81df/src/index.js#L527

I would not mind making a PR to implement this, just wanted to see if there is a reason why it can not or should not work this way, thanks!

ability to prevent keyDown handler logic

Thanks for this lib!

I'm looking to prevent the default functionality from inserting a newline when the user types cmd+enter, in order to submit a query with the editor's value. I'm not sure how that would be best handled actually, but opening an issue in case you'd be cool with it, possibly feature-creeping.

Expose lower-API to modify text and selection, and to query selection

Editor component could have public functions like:

// like HTMLTextareaElement
selectionStart: number
selectionEnd: number
setSelectionRange(start, end)
setValue(text) // raw text; should apply highlighting, preserve selection and amend history

API to selection could be needed to enable button behaviour depending on where the selection is (e. g. to implement "comment out" button if there's no comment on current line).

API to modify value can be useful for example, to implement "comment out" button mentioned above.

yarn example is not invoked in CI

example is not mentioned in .circleci or .github folders.

And locally yarn example fails on my laptop with:

% yarn example
yarn run v1.22.4
$ parcel example/index.html
(node:9237) UnhandledPromiseRejectionWarning: Error: Could not locate the bindings file. Tried:
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/build/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/build/Debug/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/build/Release/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/out/Debug/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/Debug/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/out/Release/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/Release/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/build/default/deasync.node
 → /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/compiled/14.3.0/darwin/x64/deasync.node
    at bindings (/Users/nga/devel/left/react-simple-code-editor/node_modules/bindings/bindings.js:88:9)
    at /Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/index.js:34:32
    at Object.<anonymous> (/Users/nga/devel/left/react-simple-code-editor/node_modules/deasync/index.js:76:2)
    at Module._compile (/Users/nga/devel/left/react-simple-code-editor/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (/Users/nga/devel/left/react-simple-code-editor/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/nga/devel/left/react-simple-code-editor/node_modules/parcel-bundler/src/utils/syncPromise.js:1:79)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9237) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9237) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
✨  Done in 0.30s.

(And no files created anywhere)

Without CI it's not clear, is it a problem with my setup or with the repo.

Should be possible to turn into a markdown

Instead of using a completely different component for markdown people should be able to switch between the editor and markdown so less time would be spent to match the code highlighting...

Ability to set the textarea id attribute

It would be nice to be able to set the id of the generated textarea, like we can for the name and others. I need this to be able to get a <label for='myid'>...</label> element to auto focus onto the textarea when clicked.

Great little code editor BTW. It's very useful to have a lightweight option for React.

Limit number of rows

Current behaviour

No way to limit number of rows.

Expected behaviour

Number of rows property should be exposed in the Editor component.
Normally textarea component has a rows property, for example rows="20".
I've looked in the documentation props and this doesn't seem to be available.

User-select cant be disabled

Current behaviour

User-selection can't be disabled or changed

Expected behaviour

Disabling user-selection since when you select the text area it renders the textarea and the wrapper.

Code sample

Screenshots (if applicable)

customarea

thanks, good job on this lib

Should handle vertical and horizontal overflow

Current behaviour

Editor didn't handle vertical and horizontal overflow

Expected behaviour

Editor should handle vertical and horizontal overflow (may be wrap content for handle horizontal)

Code sample

https://codesandbox.io/s/py38vl9nn0

Screenshots (if applicable)

image

What have you tried

I already tried using style={{overflow-y: 'auto', overflow-x:'auto'}} to set scroll if there an overflow content, it's show scroll for both vertical and horizontal overflow, but there is some strange bug.
If i click cursor on overflow line, and put it on the end, it's show on the max width, instead of the end of the line.
And also when i'm going to the bottom line, the cursor show on the max height, instead of the bottom of the line.

Your Environment

software version
react-simple-code-editor ^0.8.0
react ^16.7.0
npm or yarn 6.2.0
node 10.8.0
browser Google Chrome Version 72.0.3626.109

how to manage history

Current behaviour

  1. The upper limit of history stack capacity is set by internal variable HISTORY_LIMIT, with a value of 100.
  2. Editor has a property called session, which manages history data. Is it safe to modify its value to clear history? The code sample _resetHistory is in following section.

Expected behaviour

  1. Can I customize HISTORY_LIMIT, because sometimes the text content is too long.
  2. Can I modify session to clear history? If not, how to do that?

Code sample

I tried this method to clear history, which seems to work.

  _resetHistory = () => {
    let curHistory = this.editorRef.current.session.history;
    let curRecord = curHistory.stack[curHistory.offset];
    this.editorRef.current.session = {
      history: {
        stack: [curRecord],
        offset: 0,
      }
    };
  }

Screenshots (if applicable)

What have you tried

Your Environment

software version
react-simple-code-editor ^0.11.0
react ^16.12.0
npm or yarn npm 6.4.1
node 10.13.0
browser chrome 73.0

how to limit height?

I'd like to limit the height of the Editor container and have the user scroll if they want to edit content further down. I tried by setting a max-height and overflow: auto but the problem i have is that the textarea scrolls out of view.

Problem illustrated here:
https://codesandbox.io/s/lyp85pkyrq

Any idea how i can vertically limit the height?

Global Styles set with * override local element.styles

Current behaviour

Going against the intuition of css specificity, a global font style set by the user of react-simple-code-editor can override the local element.style attribute. This is most noticeable when the global font overrides the 'monospace' styling of the textarea.

Expected behaviour

Global font styles should not override the local font styles

Code sample

https://codesandbox.io/s/boring-fermat-r04c4

Screenshots (if applicable)

image

What have you tried

  • Setting styles on the components given to the end user to override specificity

Your Environment

software version
react-simple-code-editor 0.10.0
react 16.12.0

use react-syntax-highlighter

Current behaviour

任何的输入,会导<pre></pre>内元素的全量渲染,在大段代码进行更新的时候,会有一些卡顿。

Expected behaviour

在进行代码编辑的时候,只是触发那个元素的更新。

What have you tried

我正在尝试使用 prism-react-renderer 进行渲染.

Implement a focus method

Current behaviour

I'm building an advanced editor that uses "tiles" or blocks and I need to move arround using the arrow keys, so I need to programatically give focus to the editor. I can use a reference, then call the method, much more like DraftJS is doing:
https://draftjs.org/docs/advanced-topics-managing-focus

Expected behaviour

When I call a focus() method on the component, the editor gets the focus.

Code sample

It's a feature request :) If you are interested on what are we building, you can take a look at our editor here:
https://volto.kitconcept.com/

  1. Login
  2. Create a page
  3. In a text tile, click on the +, select the palette icon, then the code icon

Proposal: make a readonly ability

Current behavior

Typescript errors when omitting the onValueChanged prop.

Expected behavior

The component should be used for displaying highlighted code when it's not editable

Code sample

      return (<Editor
        value={`SELECT *`}
        highlight={code => highlight(code, languages.sql)}
        padding={10}
        style={{
          fontSize: 12,
        }}
      />)

This code sample is invalid in TypeScript because the onValueChanged is required.

Screenshots (if applicable)

What have you tried

I've tried removing the onValueChanged prop, but the typescript definitions (and likely the underlying js) require that this prop is required. In addition, the docs show that this prop is required.

Your Environment

software version
react-simple-code-editor 0.9.11
typescript 3.5.2
react 16.8.6
npm or yarn 6.9.0
node 10.15.3
browser Brave latest

word-break issue when Text is too long

Current behaviour

  • When I enter long text to the editor, first it does not show full text, 2nd the cursor stop to work.

Expected behaviour

  • Should show every text and cursor should work properly. Or may be one horizontal scroll (like GitHub does)

Code sample

Please paste the code to your official sample page

import React from "react";
import ReactDOM from "react-dom";

const a = `https://www.google.com/search?ei=ryKgXbvqOZio9QOZ_YHIAQ&q=This+should+be+long+url..+Long+text.++Long+text+Long+text+Long+text++Long+text++Long+text++Long+text&oq=This+should+be+long+url..+Long+text.++Long+text+Long+text+Long+text++Long+text++Long+text++Long+text&gs_l=psy-ab.3...5010.35688..36324...20.4..0.123.6390.31j34......0....1j2..gws-wiz.....6..0i71j0i362i308i154i357j0i273j0j0i131j0i273i70i249j0i67j0i131i273j0i10j0i22i30j33i22i29i30j33i160j33i21.z-O4QjX0nwE&ved=0ahUKEwj7_aTKy5PlAhUYVH0KHZl-ABkQ4dUDCAs&uact=5` 
function App() {
  return (
    <h1> 
    Change Url1 to Url {url1}
 </h1>
  );
}

ReactDOM.render(<App />, document.getElementById("root"));

Screenshots (if applicable)

What have you tried

I forked the repo and the change the style for <pre>tag to wordBreak: 'break-all'. And it works. But The problem is now it's breaking to every word. But this solution works for my case as I need json editor and all json contains multiple long links.

Your Environment

software version
react-simple-code-editor latest (your official doc)
react latest (your official doc)
npm or yarn latest (your official doc)
node latest (your official doc)
browser latest (your official doc My browser 😈 )

proposal: Implement render props & prop getters for customisability

I'm opening a small issue to document this discussion that has before happened "behind the scenes".

Essentially react-simple-code-editor has two major problems. Firstly, specific styles and DOM structures and attributes must be used to make the pattern work. And secondly, this leads to a problem when minor specifics need to be customised, like additional styles, style overrides, extra classNames, ID props, other custom props... — the list goes on.

Compared to the current way of writing an editor let's explore an alternative (unchanged props have been omitted)

const wrapperStyle = {
  fontFamily: '"Fira code", "Fira Mono", monospace',
  fontSize: 12
}

<Editor>
  {({ getWrapperProps, getTextareaProps, getPreProps }) => (
    <div {...getWrapperProps({ style: wrapperStyle })}>
      <textarea {...getTextareaProps()} id="editor" />
      <pre {...getPreProps({ className: 'prism-theme-dracula' })} />
    </div>
  )}
</Editor>

Line numbers CSS solution doesn't work since 0.9.2

Current behaviour

Since 0.9.2 (and this commit and this commit) it's impossible to add line numbers as it was suggested in #30 (comment) (809d5f0). Actually, markup is there, but overflow: hidden prevents line numbers from showing.

Before mentioned commit, there were no overflow: hidden and it was possible to put line numbers outside container with CSS.

Expected behaviour

Not apply overflow: hidden to container.

Code sample

https://stylelint.io/demo

Line numbers for code area and config area applied via Prism:

https://github.com/stylelint/stylelint-demo/blob/6988cac4f5bcf01999de2234193e212121ad03ee/src/common/linter/index.js#L51-L57

Screenshots (if applicable)

What have you tried

I tried to use padding option, but it supports only one number, and we'll need to use something like padding: 10px 10px 10px 65px to style properly.

style={{ padding: '10px 10px 10px 65px' }} doesn't work, because <textarea> and <pre> won't be aligned anymore.

Your Environment

software version
react-simple-code-editor 0.9.14
react 16.9.0

expose cursor position?

Would it be easy to expose the cursor position as well? Perhaps as a onCursorChange prop?
I need to know when the cursor is on the very first or very last line of a file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.