Просмотр исходного кода

Dynamically adjust the width of autocomplete popup.

Shane Kilkelly 9 лет назад
Родитель
Сommit
3ffef7fe56

+ 12 - 1
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee

@@ -282,7 +282,18 @@ define [
 						editor.completer.autoSelect = true
 						editor.completer.autoSelect = true
 						editor.completer.showPopup(editor)
 						editor.completer.showPopup(editor)
 						editor.completer.cancelContextMenu()
 						editor.completer.cancelContextMenu()
-						$(editor.completer.popup?.container).css({'font-size': @$scope.fontSize + 'px'})
+						container = $(editor.completer.popup?.container)
+						container.css({'font-size': @$scope.fontSize + 'px'})
+						# Dynamically set width of autocomplete popup
+						if filtered = editor?.completer?.completions?.filtered
+							longestCaption = _.max(filtered.map( (c) -> c.caption.length ))
+							longestMeta = _.max(filtered.map( (c) -> c.meta.length ))
+							charScale = @$scope.fontSize * 0.7
+							width = Math.min(
+								Math.round(longestCaption*charScale + longestMeta*charScale + 25),
+								700
+							)
+							container.css({width: "#{width}px"})
 						if editor.completer?.completions?.filtered?.length == 0
 						if editor.completer?.completions?.filtered?.length == 0
 							editor.completer.detach()
 							editor.completer.detach()
 					bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
 					bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"

+ 0 - 4
services/web/public/stylesheets/app/editor.less

@@ -505,7 +505,3 @@
 	border-bottom: 1px solid @modal-header-border-color;
 	border-bottom: 1px solid @modal-header-border-color;
 }
 }
 
 
-// Widen autocomplete popup
-.ace_autocomplete {
-	width: 380px !important;
-}