only resize window when it is needed
This commit is contained in:
parent
24a2479a97
commit
5738d37803
|
@ -39,7 +39,7 @@ describe Fingers::Hinter do
|
|||
alphabet = "asdf".split("")
|
||||
|
||||
hinter = Fingers::Hinter.new(
|
||||
input: input,
|
||||
input: input.split("\n"),
|
||||
width: width,
|
||||
patterns: patterns,
|
||||
state: ::Fingers::State.new,
|
||||
|
@ -82,7 +82,7 @@ Changes not staged for commit:
|
|||
alphabet = "asdf".split("")
|
||||
|
||||
hinter = Fingers::Hinter.new(
|
||||
input: input,
|
||||
input: input.split("\n"),
|
||||
width: width,
|
||||
patterns: patterns,
|
||||
state: ::Fingers::State.new,
|
||||
|
|
|
@ -65,7 +65,7 @@ module Fingers::Commands
|
|||
fingers_window.window_id,
|
||||
target_pane.pane_width,
|
||||
target_pane.pane_height,
|
||||
)
|
||||
) if needs_resize?
|
||||
|
||||
view.render
|
||||
tmux.swap_panes(fingers_window.pane_id, target_pane.pane_id)
|
||||
|
@ -83,6 +83,11 @@ module Fingers::Commands
|
|||
end
|
||||
end
|
||||
|
||||
private def needs_resize?
|
||||
pane_width = target_pane.pane_width.to_i
|
||||
pane_contents.any? { |line| line.size > pane_width }
|
||||
end
|
||||
|
||||
private def teardown
|
||||
tmux.set_key_table "root"
|
||||
|
||||
|
@ -115,13 +120,17 @@ module Fingers::Commands
|
|||
|
||||
private getter hinter : Hinter do
|
||||
Fingers::Hinter.new(
|
||||
input: tmux.capture_pane(target_pane),
|
||||
input: pane_contents,
|
||||
width: target_pane.pane_width.to_i,
|
||||
state: state,
|
||||
output: pane_printer
|
||||
)
|
||||
end
|
||||
|
||||
private getter pane_contents : Array(String) do
|
||||
tmux.capture_pane(target_pane).split("\n")
|
||||
end
|
||||
|
||||
private getter view : View do
|
||||
::Fingers::View.new(
|
||||
hinter: hinter,
|
||||
|
|
|
@ -8,13 +8,12 @@ module Fingers
|
|||
@formatter : Formatter
|
||||
@patterns : Array(String)
|
||||
@alphabet : Array(String)
|
||||
@lines : Array(String) | Nil
|
||||
@pattern : Regex | Nil
|
||||
@hints : Array(String) | Nil
|
||||
@n_matches : Int32 | Nil
|
||||
|
||||
def initialize(
|
||||
input : String,
|
||||
input : Array(String),
|
||||
width : Int32,
|
||||
state : Fingers::State,
|
||||
output : Printer,
|
||||
|
@ -23,7 +22,7 @@ module Fingers
|
|||
huffman = Huffman.new,
|
||||
formatter = ::Fingers::MatchFormatter.new
|
||||
)
|
||||
@input = input
|
||||
@lines = input
|
||||
@width = width
|
||||
@hints_by_text = {} of String => String
|
||||
@lookup_table = {} of String => String
|
||||
|
@ -133,10 +132,6 @@ module Fingers
|
|||
pattern.name_table.compact_map { |k, v| v == "capture" ? k : nil }
|
||||
end
|
||||
|
||||
def lines : Array(String)
|
||||
@lines ||= input.split("\n")
|
||||
end
|
||||
|
||||
def n_matches : Int32
|
||||
return @n_matches.as(Int32) if !@n_matches.nil?
|
||||
|
||||
|
@ -152,5 +147,7 @@ module Fingers
|
|||
|
||||
match_set.size
|
||||
end
|
||||
|
||||
private property lines : Array(String)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue