@@ -44,7 +44,6 @@ import {
4444} from 'shared/modules/settings/settingsDuck'
4545import { add } from 'shared/modules/stream/streamDuck'
4646import { Bar , ActionButtonSection , EditorWrapper , Header } from './styled'
47- import { EditorButton , EditModeEditorButton } from 'browser-components/buttons'
4847import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
4948import { deepEquals , shallowEquals } from 'services/utils'
5049import * as viewTypes from 'shared/modules/stream/frameViewTypes'
@@ -80,7 +79,6 @@ export class Editor extends Component {
8079 buffer : '' ,
8180 mode : 'cypher' ,
8281 notifications : [ ] ,
83- expanded : false ,
8482 lastPosition : { line : 0 , column : 0 } ,
8583 contentId : null ,
8684 editorHeight : 0
@@ -95,17 +93,16 @@ export class Editor extends Component {
9593 this . setEditorValue ( msg . message )
9694 } )
9795 this . props . bus . take ( FOCUS , this . focusEditor . bind ( this ) )
98- this . props . bus . take ( EXPAND , this . expandEditorToggle . bind ( this ) )
9996 }
10097 }
10198
10299 shouldComponentUpdate ( nextProps , nextState ) {
103100 return ! (
104- nextState . expanded === this . state . expanded &&
105101 nextState . contentId === this . state . contentId &&
106102 nextState . editorHeight === this . state . editorHeight &&
107103 shallowEquals ( nextState . notifications , this . state . notifications ) &&
108104 deepEquals ( nextProps . schema , this . props . schema ) &&
105+ nextProps . editorSize === this . props . editorSize &&
109106 nextProps . useDb === this . props . useDb &&
110107 nextProps . enableMultiStatementMode === this . props . enableMultiStatementMode
111108 )
@@ -116,17 +113,13 @@ export class Editor extends Component {
116113 this . codeMirror . setCursor ( this . codeMirror . lineCount ( ) , 0 )
117114 }
118115
119- expandEditorToggle ( ) {
120- this . setState ( { expanded : ! this . state . expanded } )
121- }
122-
123116 clearEditor = ( ) => {
124117 this . setEditorValue ( '' )
125118 this . setContentId ( null )
126119 }
127120
128121 handleEnter ( cm ) {
129- const multiline = cm . lineCount ( ) !== 1 || this . state . expanded
122+ const multiline = this . props . editorSize !== 'LINE'
130123 if ( multiline ) {
131124 this . newlineAndIndent ( cm )
132125 } else {
@@ -152,9 +145,9 @@ export class Editor extends Component {
152145 this . setState ( {
153146 notifications : [ ] ,
154147 historyIndex : - 1 ,
155- buffer : null ,
156- expanded : false
148+ buffer : null
157149 } )
150+ this . props . setSize ( 'LINE' )
158151 }
159152 }
160153
@@ -255,6 +248,9 @@ export class Editor extends Component {
255248 console . log ( e )
256249 }
257250 } )
251+ if ( this . props . editorRef ) {
252+ this . props . editorRef . current = this . codeMirror
253+ }
258254 }
259255
260256 getEditorValue ( ) {
@@ -400,8 +396,8 @@ export class Editor extends Component {
400396 }
401397
402398 lineNumberFormatter = line => {
403- const multiLine = this . codeMirror && this . codeMirror . lineCount ( ) > 1
404- if ( this . state . expanded || multiLine ) {
399+ const multiline = this . props . editorSize !== 'LINE'
400+ if ( multiline ) {
405401 return line
406402 } else {
407403 return `${ this . props . useDb || '' } $`
@@ -417,6 +413,13 @@ export class Editor extends Component {
417413 }
418414 }
419415
416+ goToCard ( cm ) {
417+ this . newlineAndIndent ( cm )
418+ if ( this . props . editorSize === 'LINE' ) {
419+ this . props . setSize ( 'CARD' )
420+ }
421+ }
422+
420423 render ( cm ) {
421424 const options = {
422425 lineNumbers : true ,
@@ -431,7 +434,7 @@ export class Editor extends Component {
431434 extraKeys : {
432435 'Ctrl-Space' : 'autocomplete' ,
433436 Enter : this . handleEnter . bind ( this ) ,
434- 'Shift-Enter' : this . newlineAndIndent . bind ( this ) ,
437+ 'Shift-Enter' : this . goToCard . bind ( this ) ,
435438 'Cmd-Enter' : this . execCurrent . bind ( this ) ,
436439 'Ctrl-Enter' : this . execCurrent . bind ( this ) ,
437440 'Cmd-Up' : this . historyPrev . bind ( this ) ,
@@ -461,12 +464,6 @@ export class Editor extends Component {
461464
462465 const editorIsEmpty = this . getEditorValue ( ) . length > 0
463466 const buttons = [
464- {
465- onClick : ( ) => this . setEditorValue ( '' ) ,
466- icon : eraser2 ,
467- title : 'Clear' ,
468- disabled : editorIsEmpty
469- } ,
470467 {
471468 onClick : this . state . contentId
472469 ? ( ) =>
@@ -486,18 +483,20 @@ export class Editor extends Component {
486483 onClick : this . execCurrent ,
487484 icon : controlsPlay ,
488485 title : 'Play' ,
489- disabled : editorIsEmpty
486+ disabled : editorIsEmpty ,
487+ iconColor : this . props . theme . linkHover
490488 }
491489 ]
492490
493- const cardView = this . codeMirror && this . codeMirror . lineCount ( ) !== 1
491+ const isFullscreen = this . props . editorSize === 'FULLSCREEN'
492+ const isCardSize = this . props . editorSize === 'CARD'
494493
495494 return (
496- < Bar expanded = { this . state . expanded } card = { cardView } >
497- < Header expanded = { this . state . expanded } card = { cardView } >
498- < ActionButtons buttons = { buttons } />
495+ < Bar >
496+ < Header >
497+ < ActionButtons width = { 15 } buttons = { buttons } />
499498 </ Header >
500- < EditorWrapper expanded = { this . state . expanded } card = { cardView } >
499+ < EditorWrapper fullscreen = { isFullscreen } cardSize = { isCardSize } >
501500 < Codemirror
502501 ref = { ref => {
503502 this . editor = ref
0 commit comments