|
4 | 4 | * - Removal of line 1 to 15, awaiting https://github.com/Ionaru/easy-markdown-editor/pull/263 |
5 | 5 | * - Added `moveToNextField()` and `moveToPreviousField()` functions, and changed `Tab` and `Shift-Tab` key bindings to only indent the content when there is a selection in the editor. See https://github.com/filamentphp/filament/pull/16144. |
6 | 6 | * - Wrapped the indent/outdent operations in `toggleCodeBlock()` in `cm.operation()` so they group into a single CodeMirror undo step. See https://github.com/filamentphp/filament/pull/19890. |
| 7 | + * - Changed `minHeight` and `maxHeight` to apply independently when both options are set. See https://github.com/Ionaru/easy-markdown-editor/issues/413. |
7 | 8 | */ |
8 | 9 |
|
9 | 10 | // Some variables |
@@ -441,11 +442,18 @@ function toggleFullScreen(editor) { |
441 | 442 |
|
442 | 443 | // Remove or set maxHeight |
443 | 444 | if (typeof editor.options.maxHeight !== 'undefined') { |
| 445 | + var heightProperty = editor.hasExplicitMinHeight |
| 446 | + ? 'max-height' |
| 447 | + : 'height' |
| 448 | + |
444 | 449 | if (cm.getOption('fullScreen')) { |
445 | | - cm.getScrollerElement().style.removeProperty('height') |
446 | | - sidebyside.style.removeProperty('height') |
| 450 | + cm.getScrollerElement().style.removeProperty(heightProperty) |
| 451 | + sidebyside.style.removeProperty(heightProperty) |
447 | 452 | } else { |
448 | | - cm.getScrollerElement().style.height = editor.options.maxHeight |
| 453 | + cm.getScrollerElement().style.setProperty( |
| 454 | + heightProperty, |
| 455 | + editor.options.maxHeight, |
| 456 | + ) |
449 | 457 | editor.setPreviewMaxHeight() |
450 | 458 | } |
451 | 459 | } |
@@ -1924,6 +1932,8 @@ function EasyMDE(options) { |
1924 | 1932 | // Handle options parameter |
1925 | 1933 | options = options || {} |
1926 | 1934 |
|
| 1935 | + this.hasExplicitMinHeight = Boolean(options.minHeight) |
| 1936 | + |
1927 | 1937 | // Used later to refer to it"s parent |
1928 | 1938 | options.parent = this |
1929 | 1939 |
|
@@ -2049,8 +2059,12 @@ function EasyMDE(options) { |
2049 | 2059 |
|
2050 | 2060 | options.direction = options.direction || 'ltr' |
2051 | 2061 |
|
2052 | | - if (typeof options.maxHeight !== 'undefined') { |
2053 | | - // Min and max height are equal if maxHeight is set |
| 2062 | + if ( |
| 2063 | + typeof options.maxHeight !== 'undefined' && |
| 2064 | + !this.hasExplicitMinHeight |
| 2065 | + ) { |
| 2066 | + // Preserve the fixed-height behavior introduced in |
| 2067 | + // https://github.com/Ionaru/easy-markdown-editor/pull/222 |
2054 | 2068 | options.minHeight = options.maxHeight |
2055 | 2069 | } else { |
2056 | 2070 | options.minHeight = options.minHeight || '300px' |
@@ -2521,7 +2535,12 @@ EasyMDE.prototype.render = function (el) { |
2521 | 2535 | this.codemirror.getScrollerElement().style.minHeight = options.minHeight |
2522 | 2536 |
|
2523 | 2537 | if (typeof options.maxHeight !== 'undefined') { |
2524 | | - this.codemirror.getScrollerElement().style.height = options.maxHeight |
| 2538 | + this.codemirror |
| 2539 | + .getScrollerElement() |
| 2540 | + .style.setProperty( |
| 2541 | + this.hasExplicitMinHeight ? 'max-height' : 'height', |
| 2542 | + options.maxHeight, |
| 2543 | + ) |
2525 | 2544 | } |
2526 | 2545 |
|
2527 | 2546 | if (options.forceSync === true) { |
@@ -3004,18 +3023,22 @@ EasyMDE.prototype.setPreviewMaxHeight = function () { |
3004 | 3023 | var cm = this.codemirror |
3005 | 3024 | var wrapper = cm.getWrapperElement() |
3006 | 3025 | var preview = wrapper.nextSibling |
3007 | | - |
3008 | | - // Calc preview max height |
3009 | | - var paddingTop = parseInt(window.getComputedStyle(wrapper).paddingTop) |
3010 | | - var borderTopWidth = parseInt( |
3011 | | - window.getComputedStyle(wrapper).borderTopWidth, |
| 3026 | + var wrapperStyle = window.getComputedStyle(wrapper) |
| 3027 | + |
| 3028 | + preview.style.setProperty( |
| 3029 | + this.hasExplicitMinHeight ? 'max-height' : 'height', |
| 3030 | + 'calc(' + |
| 3031 | + this.options.maxHeight + |
| 3032 | + ' + ' + |
| 3033 | + wrapperStyle.paddingTop + |
| 3034 | + ' + ' + |
| 3035 | + wrapperStyle.paddingBottom + |
| 3036 | + ' + ' + |
| 3037 | + wrapperStyle.borderTopWidth + |
| 3038 | + ' + ' + |
| 3039 | + wrapperStyle.borderBottomWidth + |
| 3040 | + ')', |
3012 | 3041 | ) |
3013 | | - var optionsMaxHeight = parseInt(this.options.maxHeight) |
3014 | | - var wrapperMaxHeight = |
3015 | | - optionsMaxHeight + paddingTop * 2 + borderTopWidth * 2 |
3016 | | - var previewMaxHeight = wrapperMaxHeight.toString() + 'px' |
3017 | | - |
3018 | | - preview.style.height = previewMaxHeight |
3019 | 3042 | } |
3020 | 3043 |
|
3021 | 3044 | EasyMDE.prototype.createSideBySide = function () { |
|
0 commit comments