Skip to content

Commit

Permalink
fix: properly handle tab characters
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 29, 2019
1 parent 360e415 commit 394c159
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The editor accepts all the props accepted by `textarea`. In addition, you can pa
- `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`](https://prismjs.com).
- `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`.
- `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`.
Expand Down
1 change: 1 addition & 0 deletions example/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body {
}

.container_editor_area {
tab-size: 4ch;
max-height: 400px;
overflow: auto;
margin: 1.67em 0;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default class Editor extends React.Component<Props, State> {

const { value, selectionStart, selectionEnd } = e.target;

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

if (e.keyCode === KEYCODE_TAB && !ignoreTabKey && this.state.capture) {
// Prevent focus change
Expand Down

0 comments on commit 394c159

Please sign in to comment.