Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Editor extends Component {
}

onKeyDown = evt => {
if (this.props.onKeyDown) {
this.props.onKeyDown(evt)
}
if (evt.keyCode === 9) { // Tab Key
document.execCommand('insertHTML', false, '&#009')
evt.preventDefault()
Expand All @@ -125,6 +128,9 @@ class Editor extends Component {
}

onKeyUp = evt => {
if (this.props.onKeyUp) {
this.props.onKeyUp(evt)
}
if (
evt.keyCode === 91 || // left cmd
evt.keyCode === 93 || // right cmd
Expand Down Expand Up @@ -158,7 +164,10 @@ class Editor extends Component {
this._doUndo = 0
}

onClick = () => {
onClick = evt => {
if (this.props.onClick) {
this.props.onClick(evt)
}
this.undoTimestamp = 0 // Reset timestamp
this.selection = selectionRange(this.ref)
}
Expand Down Expand Up @@ -188,11 +197,14 @@ class Editor extends Component {
}

render() {
const { contentEditable, className, style } = this.props
const { contentEditable, className, style, ...rest } = this.props
const { html } = this.state
delete rest.children;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rather non obvious v8 perf hog :) can you just manually set code to undefined for presentations below? Also you don't need to do anything about children

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I don't think the lifetime of rest is such that it will be affected by the V8 issue, but I shall make the change requested and leave children alone.

Copy link
Contributor Author

@webOS101 webOS101 May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, setting it to undefined does not have the desired effect. It's still a property on rest and causes a React warning: Unknown prop code on <pre> tag. I removed the delete on children and the unneeded semicolon. The only other option is destructuring out code and ignoring it, but I don't like unused parameter warnings much.

delete rest.code;

return (
<pre
{...rest}
ref={this.onRef}
className={cn('prism-code', className)}
style={style}
Expand Down
5 changes: 2 additions & 3 deletions src/components/Live/LiveEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import React from 'react'
import { LiveContextTypes } from './LiveProvider'
import Editor from '../Editor'

const LiveEditor = ({ className, style }, { live }) => (
const LiveEditor = (props, { live }) => (
<Editor
className={className}
style={style}
{...props}
code={live.code}
onChange={live.onChange}
/>
Expand Down