From 20d7df51398f15aba540c53beb137dac919e01b8 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 4 Feb 2020 14:36:19 +0800 Subject: [PATCH] Handle theme dropdown menu resizing Signed-off-by: Yukai Huang --- public/js/lib/editor/index.js | 22 +++++++++++++++++++++- public/js/lib/editor/statusbar.html | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js index f622e798..a937f47e 100644 --- a/public/js/lib/editor/index.js +++ b/public/js/lib/editor/index.js @@ -1,12 +1,15 @@ /* global CodeMirror, $, editor, Cookies */ +import { options, Alignment, FormatType } from '@susisu/mte-kernel' +import debounce from 'lodash/debounce' + import * as utils from './utils' import config from './config' import statusBarTemplate from './statusbar.html' import toolBarTemplate from './toolbar.html' import './markdown-lint' import { initTableEditor } from './table-editor' -import { options, Alignment, FormatType } from '@susisu/mte-kernel' import { availableThemes } from './constants' +import { } from './ui-elements' /* config section */ const isMac = CodeMirror.keyMap.default === CodeMirror.keyMap.macDefault @@ -326,6 +329,8 @@ export default class Editor { this.setSpellcheck() this.setLinter() this.setPreferences() + + this.handleStatusBarResize() } updateStatusBar () { @@ -350,6 +355,21 @@ export default class Editor { } } + handleStatusBarResize () { + const onResize = debounce(() => { + if (!this.statusBar) { + return + } + + const maxHeight = window.innerHeight - this.statusBar.height() - 50 /* navbar height */ - 10 /* spacing */ + this.statusBar.find('.status-theme ul.dropdown-menu').css('max-height', `${maxHeight}px`) + }, 300) + + $(window).resize(onResize) + + onResize() + } + setIndent () { var cookieIndentType = Cookies.get('indent_type') var cookieTabSize = parseInt(Cookies.get('tab_size')) diff --git a/public/js/lib/editor/statusbar.html b/public/js/lib/editor/statusbar.html index eddaa04b..5cee8998 100644 --- a/public/js/lib/editor/statusbar.html +++ b/public/js/lib/editor/statusbar.html @@ -31,11 +31,11 @@
4
-
+
-