-
Notifications
You must be signed in to change notification settings - Fork 479
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
Javalab: Use codemirror #39147
Merged
Merged
Javalab: Use codemirror #39147
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
69b1477
try out code mirror
molly-moen eed477b
fix merge conflict
molly-moen 1526cdc
fix merge conflict
molly-moen c4e0b7d
remove ace editor
molly-moen d001304
update background color
molly-moen 324ea99
sync editor changes to redux
molly-moen 676477b
fix comment
molly-moen 91bf286
allow tabs in editor
molly-moen db98084
Merge remote-tracking branch 'origin/staging' into java-ide-codemirror
molly-moen c991dd1
add comment
molly-moen fd71b31
Merge remote-tracking branch 'origin/staging' into java-ide-codemirror
molly-moen 9965fe9
fix build issues and refactor setup
molly-moen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import React from 'react'; | ||
import $ from 'jquery'; | ||
import AceEditor from 'react-ace'; | ||
import {connect} from 'react-redux'; | ||
import {setEditorText} from './javalabRedux'; | ||
import PropTypes from 'prop-types'; | ||
import PaneHeader, {PaneSection} from '@cdo/apps/templates/PaneHeader'; | ||
import 'ace-builds/src-noconflict/mode-java'; | ||
import 'ace-builds/src-noconflict/theme-monokai'; | ||
import {EditorState, basicSetup} from '@codemirror/basic-setup'; | ||
import {java} from '@codemirror/lang-java'; | ||
import {oneDarkTheme, oneDarkHighlightStyle} from '@codemirror/theme-one-dark'; | ||
import {EditorView, keymap} from '@codemirror/view'; | ||
import {defaultTabBinding} from '@codemirror/commands'; | ||
|
||
const style = { | ||
editor: { | ||
width: '100%', | ||
height: 600 | ||
height: 600, | ||
backgroundColor: '#282c34' | ||
} | ||
}; | ||
|
||
|
@@ -23,32 +25,41 @@ class JavalabEditor extends React.Component { | |
setEditorText: PropTypes.func | ||
}; | ||
|
||
onChange = newValue => { | ||
this.props.setEditorText(newValue); | ||
}; | ||
|
||
componentDidMount() { | ||
let textInput = $('.ace_text-input'); | ||
if (textInput) { | ||
let textInputElement = textInput.first(); | ||
textInputElement.attr('aria-label', 'java editor panel'); | ||
} | ||
this.editor = new EditorView({ | ||
state: EditorState.create({ | ||
extensions: [ | ||
basicSetup, | ||
java(), | ||
keymap.of([defaultTabBinding]), | ||
oneDarkTheme, | ||
oneDarkHighlightStyle | ||
] | ||
}), | ||
parent: this._codeMirror, | ||
dispatch: this.dispatchEditorChange() | ||
}); | ||
} | ||
|
||
dispatchEditorChange = () => { | ||
return tr => { | ||
// we are overwriting the default dispatch method for codemirror, | ||
// so we need to manually call the update method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commenting is very helpful :) |
||
this.editor.update([tr]); | ||
// if there are changes to the editor, update redux. | ||
if (!tr.changes.empty && tr.newDoc) { | ||
this.props.setEditorText(tr.newDoc.toString()); | ||
} | ||
}; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div style={this.props.style}> | ||
<PaneHeader hasFocus={true}> | ||
<PaneSection>Editor</PaneSection> | ||
</PaneHeader> | ||
<AceEditor | ||
mode="java" | ||
theme="monokai" | ||
onChange={this.onChange} | ||
name="java-lab-editor" | ||
editorProps={{$blockScrolling: true}} | ||
style={style.editor} | ||
/> | ||
<div ref={el => (this._codeMirror = el)} style={style.editor} /> | ||
</div> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
tr
in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr is a codemirror transaction I'll add a comment to make it more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍