@@ -14,7 +14,11 @@ export class MarkdownEditor extends Component {
1414
1515 this . display = this . $refs . display ;
1616 this . input = this . $refs . input ;
17- this . settingContainer = this . $refs . settingContainer ;
17+ this . divider = this . $refs . divider ;
18+ this . displayWrap = this . $refs . displayWrap ;
19+
20+ const settingContainer = this . $refs . settingContainer ;
21+ const settingInputs = settingContainer . querySelectorAll ( 'input[type="checkbox"]' ) ;
1822
1923 this . editor = null ;
2024 initEditor ( {
@@ -23,11 +27,11 @@ export class MarkdownEditor extends Component {
2327 displayEl : this . display ,
2428 inputEl : this . input ,
2529 drawioUrl : this . getDrawioUrl ( ) ,
30+ settingInputs : Array . from ( settingInputs ) ,
2631 text : {
2732 serverUploadLimit : this . serverUploadLimitText ,
2833 imageUploadError : this . imageUploadErrorText ,
2934 } ,
30- settings : this . loadSettings ( ) ,
3135 } ) . then ( editor => {
3236 this . editor = editor ;
3337 this . setupListeners ( ) ;
@@ -76,30 +80,40 @@ export class MarkdownEditor extends Component {
7680 toolbarLabel . closest ( '.markdown-editor-wrap' ) . classList . add ( 'active' ) ;
7781 } ) ;
7882
79- // Setting changes
80- this . settingContainer . addEventListener ( 'change' , e => {
81- const actualInput = e . target . parentNode . querySelector ( 'input[type="hidden"]' ) ;
82- const name = actualInput . getAttribute ( 'name' ) ;
83- const value = actualInput . getAttribute ( 'value' ) ;
84- window . $http . patch ( '/preferences/update-boolean' , { name, value} ) ;
85- this . editor . settings . set ( name , value === 'true' ) ;
86- } ) ;
87-
8883 // Refresh CodeMirror on container resize
8984 const resizeDebounced = debounce ( ( ) => this . editor . cm . refresh ( ) , 100 , false ) ;
9085 const observer = new ResizeObserver ( resizeDebounced ) ;
9186 observer . observe ( this . elem ) ;
92- }
9387
94- loadSettings ( ) {
95- const settings = { } ;
96- const inputs = this . settingContainer . querySelectorAll ( 'input[type="hidden"]' ) ;
88+ this . handleDividerDrag ( ) ;
89+ }
9790
98- for ( const input of inputs ) {
99- settings [ input . getAttribute ( 'name' ) ] = input . value === 'true' ;
91+ handleDividerDrag ( ) {
92+ this . divider . addEventListener ( 'pointerdown' , event => {
93+ const wrapRect = this . elem . getBoundingClientRect ( ) ;
94+ const moveListener = ( event ) => {
95+ const xRel = event . pageX - wrapRect . left ;
96+ const xPct = Math . min ( Math . max ( 20 , Math . floor ( ( xRel / wrapRect . width ) * 100 ) ) , 80 ) ;
97+ this . displayWrap . style . flexBasis = `${ 100 - xPct } %` ;
98+ this . editor . settings . set ( 'editorWidth' , xPct ) ;
99+ } ;
100+ const upListener = ( event ) => {
101+ window . removeEventListener ( 'pointermove' , moveListener ) ;
102+ window . removeEventListener ( 'pointerup' , upListener ) ;
103+ this . display . style . pointerEvents = null ;
104+ document . body . style . userSelect = null ;
105+ this . editor . cm . refresh ( ) ;
106+ } ;
107+
108+ this . display . style . pointerEvents = 'none' ;
109+ document . body . style . userSelect = 'none' ;
110+ window . addEventListener ( 'pointermove' , moveListener ) ;
111+ window . addEventListener ( 'pointerup' , upListener ) ;
112+ } ) ;
113+ const widthSetting = this . editor . settings . get ( 'editorWidth' ) ;
114+ if ( widthSetting ) {
115+ this . displayWrap . style . flexBasis = `${ 100 - widthSetting } %` ;
100116 }
101-
102- return settings ;
103117 }
104118
105119 scrollToTextIfNeeded ( ) {
0 commit comments