|
|
@ -30,25 +30,10 @@ function searchLanguage(l) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Carbon extends React.PureComponent {
|
|
|
|
class Carbon extends React.PureComponent {
|
|
|
|
static modesLoaded = new Set()
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
static defaultProps = {
|
|
|
|
onChange: () => {}
|
|
|
|
onChange: () => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
|
|
LANGUAGES.filter(language => language.mode !== 'auto' && language.mode !== 'text').forEach(
|
|
|
|
|
|
|
|
language => {
|
|
|
|
|
|
|
|
if (language.mode && !Carbon.modesLoaded.has(language.mode)) {
|
|
|
|
|
|
|
|
// TODO useLayoutEffect
|
|
|
|
|
|
|
|
language.custom
|
|
|
|
|
|
|
|
? require(`../lib/custom/modes/${language.mode}`)
|
|
|
|
|
|
|
|
: require(`codemirror/mode/${language.mode}/${language.mode}`)
|
|
|
|
|
|
|
|
Carbon.modesLoaded.add(language.mode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleLanguageChange = debounce(
|
|
|
|
handleLanguageChange = debounce(
|
|
|
|
(newCode, language) => {
|
|
|
|
(newCode, language) => {
|
|
|
|
if (language === 'auto') {
|
|
|
|
if (language === 'auto') {
|
|
|
@ -279,11 +264,25 @@ class Carbon extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function LineNumbersCarbon(props, ref) {
|
|
|
|
const modesLoaded = new Set()
|
|
|
|
|
|
|
|
function CarbonContainer(props, ref) {
|
|
|
|
const [selectedLines, setSelected] = React.useState({})
|
|
|
|
const [selectedLines, setSelected] = React.useState({})
|
|
|
|
const editorRef = React.useRef(null)
|
|
|
|
const editorRef = React.useRef(null)
|
|
|
|
const prevLine = React.useRef(null)
|
|
|
|
const prevLine = React.useRef(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
|
|
|
LANGUAGES.filter(language => language.mode !== 'auto' && language.mode !== 'text').forEach(
|
|
|
|
|
|
|
|
language => {
|
|
|
|
|
|
|
|
if (language.mode && !modesLoaded.has(language.mode)) {
|
|
|
|
|
|
|
|
language.custom
|
|
|
|
|
|
|
|
? require(`../lib/custom/modes/${language.mode}`)
|
|
|
|
|
|
|
|
: require(`codemirror/mode/${language.mode}/${language.mode}`)
|
|
|
|
|
|
|
|
modesLoaded.add(language.mode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
function onGutterClick(editor, lineNumber, gutter, e) {
|
|
|
|
function onGutterClick(editor, lineNumber, gutter, e) {
|
|
|
|
setSelected(currState => {
|
|
|
|
setSelected(currState => {
|
|
|
|
const newState = {}
|
|
|
|
const newState = {}
|
|
|
@ -330,4 +329,4 @@ function LineNumbersCarbon(props, ref) {
|
|
|
|
return <Carbon {...props} innerRef={ref} editorRef={editorRef} onGutterClick={onGutterClick} />
|
|
|
|
return <Carbon {...props} innerRef={ref} editorRef={editorRef} onGutterClick={onGutterClick} />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default React.forwardRef(LineNumbersCarbon)
|
|
|
|
export default React.forwardRef(CarbonContainer)
|
|
|
|