Skip to content
This repository
Browse code

Add g:CommandTMinHeight option

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information...
commit cda68413513995787434cd8a07a34c6adb20c8d1 1 parent da9f6b6
Nate Kane authored August 23, 2011 wincent committed February 20, 2012
7  doc/command-t.txt
@@ -431,6 +431,13 @@ Following is a list of all available options:
431 431
       If set to 0, the window will occupy as much of the available space as
432 432
       needed to show matching entries.
433 433
 
  434
+                                               *g:CommandTMinHeight*
  435
+  |g:CommandTMinHeight|                          number (default: 0)
  436
+
  437
+      The minimum height in lines the match window is allowed to shrink to.
  438
+      If set to 0, will default to a single line. If set above the max height,
  439
+      will default to |g:CommandTMaxHeight|.
  440
+
434 441
                                                *g:CommandTAlwaysShowDotFiles*
435 442
   |g:CommandTAlwaysShowDotFiles|                 boolean (default: 0)
436 443
 
12  ruby/command-t/controller.rb
@@ -81,6 +81,7 @@ def hide
81 81
 
82 82
     def flush
83 83
       @max_height   = nil
  84
+      @min_height   = nil
84 85
       @file_finder  = nil
85 86
       @tag_finder   = nil
86 87
     end
@@ -170,7 +171,8 @@ def show
170 171
       @match_window     = MatchWindow.new \
171 172
         :prompt               => @prompt,
172 173
         :match_window_at_top  => get_bool('g:CommandTMatchWindowAtTop'),
173  
-        :match_window_reverse => get_bool('g:CommandTMatchWindowReverse')
  174
+        :match_window_reverse => get_bool('g:CommandTMatchWindowReverse'),
  175
+        :min_height           => min_height
174 176
       @focus            = @prompt
175 177
       @prompt.focus
176 178
       register_for_key_presses
@@ -181,6 +183,14 @@ def max_height
181 183
       @max_height ||= get_number('g:CommandTMaxHeight') || 0
182 184
     end
183 185
 
  186
+    def min_height
  187
+      @min_height ||= begin
  188
+        min_height = get_number('g:CommandTMinHeight') || 0
  189
+        min_height = max_height if max_height != 0 && min_height > max_height
  190
+        min_height
  191
+      end
  192
+    end
  193
+
184 194
     def get_number name
185 195
       VIM::exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil
186 196
     end
8  ruby/command-t/match_window.rb
@@ -34,6 +34,7 @@ class MatchWindow
34 34
     def initialize options = {}
35 35
       @prompt = options[:prompt]
36 36
       @reverse_list = options[:match_window_reverse]
  37
+      @min_height = options[:min_height]
37 38
 
38 39
       # save existing window dimensions so we can restore them later
39 40
       @windows = []
@@ -250,7 +251,7 @@ def print_error msg
250 251
       return unless VIM::Window.select(@window)
251 252
       unlock
252 253
       clear
253  
-      @window.height = 1
  254
+      @window.height = @min_height > 0 ? @min_height : 1
254 255
       @@buffer[1] = "-- #{msg} --"
255 256
       lock
256 257
     end
@@ -279,7 +280,7 @@ def restore_window_dimensions
279 280
     end
280 281
 
281 282
     def match_text_for_idx idx
282  
-      match = truncated_match @matches[idx]
  283
+      match = truncated_match @matches[idx].to_s
283 284
       if idx == @selection
284 285
         prefix = @@selection_marker
285 286
         suffix = padding_for_selected_match match
@@ -311,7 +312,8 @@ def print_matches
311 312
         @window_width = @window.width # update cached value
312 313
         max_lines = VIM::Screen.lines - 5
313 314
         max_lines = 1 if max_lines < 0
314  
-        actual_lines = match_count > max_lines ? max_lines : match_count
  315
+        actual_lines = match_count < @min_height ? @min_height : match_count
  316
+        actual_lines = max_lines if actual_lines > max_lines
315 317
         @window.height = actual_lines
316 318
         (1..actual_lines).each do |line|
317 319
           idx = line - 1

0 notes on commit cda6841

Please sign in to comment.
Something went wrong with that request. Please try again.