Skip to content
Snippets Groups Projects
Commit 4b6da262 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome] update codemirror wrt fontSize

parent 4ae390bc
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,15 @@ import 'codemirror/lib/codemirror.css' ; ...@@ -19,6 +19,15 @@ import 'codemirror/lib/codemirror.css' ;
const CSS_HOVERED = 'dome-xText-hover' ; const CSS_HOVERED = 'dome-xText-hover' ;
const CSS_SELECTED = 'dome-xText-select' ; const CSS_SELECTED = 'dome-xText-select' ;
const getConfig = ({
buffer,
selection,
onSelection,
onContextMenu,
fontSize,
...config
}) => config;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Code Mirror Instance Wrapper // --- Code Mirror Instance Wrapper
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -53,15 +62,9 @@ class CodeMirrorWrapper extends React.Component { ...@@ -53,15 +62,9 @@ class CodeMirrorWrapper extends React.Component {
this.rootElement = elt ; this.rootElement = elt ;
if (elt) { if (elt) {
// Mounting... // Mounting...
const { buffer, const { buffer } = this.props;
selection, /* ignored */ const config = getConfig(this.props);
onSelection, /* ignored */ const cm = this.codeMirror = new CodeMirror(elt, { value: '' });
onContextMenu, /* ignored */
fontSize, /* ignored */
className, /* ignored */
style, /* ignored */
...config } = this.props ;
const cm = this.codeMirror = new CodeMirror(elt, { value: "" });
if (buffer) buffer.link(cm); if (buffer) buffer.link(cm);
// Passing all options to constructor does not work (Cf. CodeMirror's BTS) // Passing all options to constructor does not work (Cf. CodeMirror's BTS)
for (var opt in config) cm.setOption( opt , config[opt] ); for (var opt in config) cm.setOption( opt , config[opt] );
...@@ -285,17 +288,23 @@ class CodeMirrorWrapper extends React.Component { ...@@ -285,17 +288,23 @@ class CodeMirrorWrapper extends React.Component {
const cm = this.codeMirror ; const cm = this.codeMirror ;
if (cm) { if (cm) {
// Swap documents if necessary // Swap documents if necessary
const { buffer:oldBuffer, const {
selection:oldSelect, buffer:oldBuffer,
...oldConfig } = this.props ; selection:oldSelect,
const { buffer:newBuffer, fontSize:oldFont
selection:newSelect, } = this.props;
...newConfig } = newProps ; const {
buffer:newBuffer,
selection:newSelect,
fontSize:newFont
} = newProps ;
if (oldBuffer !== newBuffer) { if (oldBuffer !== newBuffer) {
if (oldBuffer) oldBuffer.unlink(cm); if (oldBuffer) oldBuffer.unlink(cm);
if (newBuffer) newBuffer.link(cm); if (newBuffer) newBuffer.link(cm);
else cm.clear(); else cm.clear();
} }
const oldConfig = getConfig(this.props);
const newConfig = getConfig(newProps);
// Incremental update options // Incremental update options
var opt ; var opt ;
for ( opt in oldConfig ) if (!(opt in newConfig)) { for ( opt in oldConfig ) if (!(opt in newConfig)) {
...@@ -315,6 +324,8 @@ class CodeMirrorWrapper extends React.Component { ...@@ -315,6 +324,8 @@ class CodeMirrorWrapper extends React.Component {
if (oldSelect) this._unmarkElementsWith( CSS_SELECTED ); if (oldSelect) this._unmarkElementsWith( CSS_SELECTED );
if (newSelect) this._markElementsWith( 'dome-xMark-' + newSelect, CSS_SELECTED ); if (newSelect) this._markElementsWith( 'dome-xMark-' + newSelect, CSS_SELECTED );
} }
// Refresh on new font
if ( oldFont !== newFont ) setImmediate(this.refresh);
} }
// Keep mounted node unchanged // Keep mounted node unchanged
return false; return false;
...@@ -390,12 +401,14 @@ class CodeMirrorWrapper extends React.Component { ...@@ -390,12 +401,14 @@ class CodeMirrorWrapper extends React.Component {
*/ */
export function Text(props) { export function Text(props) {
const { className, style, fontSize, ...config } = props ; let { className, style, fontSize, ...cmprops } = props ;
if (fontSize < 4) fontSize = 4;
if (fontSize > 48) fontSize = 48;
const theStyle = Object.assign( {} , style ); const theStyle = Object.assign( {} , style );
if (fontSize) theStyle.fontSize = fontSize ; theStyle.fontSize = fontSize ;
return ( return (
<Vfill className={className} style={theStyle}> <Vfill className={className} style={theStyle}>
<CodeMirrorWrapper {...config}/> <CodeMirrorWrapper fontSize={fontSize} {...cmprops}/>
</Vfill> </Vfill>
); );
} }
......
...@@ -95,8 +95,8 @@ const ASTview = () => { ...@@ -95,8 +95,8 @@ const ASTview = () => {
}, [buffer, theMarker]); }, [buffer, theMarker]);
// Callbacks // Callbacks
const zoomIn = () => setFontSize(fontSize + 2); const zoomIn = () => fontSize < 48 && setFontSize(fontSize + 2);
const zoomOut = () => setFontSize(fontSize - 2); const zoomOut = () => fontSize > 4 && setFontSize(fontSize - 2);
const onSelection = (marker: any) => setSelect({ marker }); const onSelection = (marker: any) => setSelect({ marker });
// Theme Popup // Theme Popup
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment