Skip to content

Commit

Permalink
Record and restore window widths
Browse files Browse the repository at this point in the history
Previously we stored and restored only window heights. It's been pointed
out, however, that when using Command-T Vim will reset horizontal sizes
for vertically-split windows as well, so we need to store and restore
window widths as well.

Based on patch posted by anonymous submitter here:

  https://wincent.com/issues/1896

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information
wincent committed Nov 6, 2011
1 parent 056c06e commit d563170
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ruby/command-t/match_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def initialize options = {}
# save existing window dimensions so we can restore them later
@windows = []
(0..(::VIM::Window.count - 1)).each do |i|
window = OpenStruct.new :index => i, :height => ::VIM::Window[i].height
@windows << window
@windows << OpenStruct.new(:index => i,
:height => ::VIM::Window[i].height,
:width => ::VIM::Window[i].width)
end

# global settings (must manually save and restore)
Expand Down Expand Up @@ -249,16 +250,25 @@ def print_error msg
end

def restore_window_dimensions
# sort from tallest to shortest
@windows.sort! { |a, b| b.height <=> a.height }
# sort from tallest to shortest, tie-breaking on window width
@windows.sort! do |a, b|
order = b.height <=> a.height
if order.zero?
b.width <=> a.width
else
order
end
end

# starting with the tallest ensures that there are no constraints
# preventing windows on the side of vertical splits from regaining
# their original full size
@windows.each do |w|
# beware: window may be nil
window = ::VIM::Window[w.index]
window.height = w.height if window
if window = ::VIM::Window[w.index]
window.height = w.height
window.width = w.width
end
end
end

Expand Down

0 comments on commit d563170

Please sign in to comment.