Permalink
Browse files

Add g:CommandTMinHeight option

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information...
1 parent da9f6b6 commit cda68413513995787434cd8a07a34c6adb20c8d1 @nathanaelkane nathanaelkane committed with Aug 23, 2011
Showing with 23 additions and 4 deletions.
  1. +7 −0 doc/command-t.txt
  2. +11 −1 ruby/command-t/controller.rb
  3. +5 −3 ruby/command-t/match_window.rb
View
@@ -431,6 +431,13 @@ Following is a list of all available options:
If set to 0, the window will occupy as much of the available space as
needed to show matching entries.
+ *g:CommandTMinHeight*
+ |g:CommandTMinHeight| number (default: 0)
+
+ The minimum height in lines the match window is allowed to shrink to.
+ If set to 0, will default to a single line. If set above the max height,
+ will default to |g:CommandTMaxHeight|.
+
*g:CommandTAlwaysShowDotFiles*
|g:CommandTAlwaysShowDotFiles| boolean (default: 0)
@@ -81,6 +81,7 @@ def hide
def flush
@max_height = nil
+ @min_height = nil
@file_finder = nil
@tag_finder = nil
end
@@ -170,7 +171,8 @@ def show
@match_window = MatchWindow.new \
:prompt => @prompt,
:match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'),
- :match_window_reverse => get_bool('g:CommandTMatchWindowReverse')
+ :match_window_reverse => get_bool('g:CommandTMatchWindowReverse'),
+ :min_height => min_height
@focus = @prompt
@prompt.focus
register_for_key_presses
@@ -181,6 +183,14 @@ def max_height
@max_height ||= get_number('g:CommandTMaxHeight') || 0
end
+ def min_height
+ @min_height ||= begin
+ min_height = get_number('g:CommandTMinHeight') || 0
+ min_height = max_height if max_height != 0 && min_height > max_height
+ min_height
+ end
+ end
+
def get_number name
VIM::exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil
end
@@ -34,6 +34,7 @@ class MatchWindow
def initialize options = {}
@prompt = options[:prompt]
@reverse_list = options[:match_window_reverse]
+ @min_height = options[:min_height]
# save existing window dimensions so we can restore them later
@windows = []
@@ -250,7 +251,7 @@ def print_error msg
return unless VIM::Window.select(@window)
unlock
clear
- @window.height = 1
+ @window.height = @min_height > 0 ? @min_height : 1
@@buffer[1] = "-- #{msg} --"
lock
end
@@ -279,7 +280,7 @@ def restore_window_dimensions
end
def match_text_for_idx idx
- match = truncated_match @matches[idx]
+ match = truncated_match @matches[idx].to_s
if idx == @selection
prefix = @@selection_marker
suffix = padding_for_selected_match match
@@ -311,7 +312,8 @@ def print_matches
@window_width = @window.width # update cached value
max_lines = VIM::Screen.lines - 5
max_lines = 1 if max_lines < 0
- actual_lines = match_count > max_lines ? max_lines : match_count
+ actual_lines = match_count < @min_height ? @min_height : match_count
+ actual_lines = max_lines if actual_lines > max_lines
@window.height = actual_lines
(1..actual_lines).each do |line|
idx = line - 1

0 comments on commit cda6841

Please sign in to comment.