mirror of
https://github.com/Morantron/tmux-fingers.git
synced 2026-09-10 07:26:32 -04:00
fix highlight when submatch is at the beginning of match
This commit is contained in:
parent
5cf72accd9
commit
8433feea47
|
|
@ -3,11 +3,11 @@ require "../../../src/fingers/dirs"
|
|||
require "../../../src/fingers/match_formatter"
|
||||
|
||||
def setup(
|
||||
hint_style : String = "#[fg=yellow,bold]",
|
||||
highlight_style : String = "#[fg=yellow]",
|
||||
hint_style : String = "#[hint]",
|
||||
highlight_style : String = "#[highlight]",
|
||||
hint_position : String = "left",
|
||||
selected_hint_style : String = "#[fg=green,bold]",
|
||||
selected_highlight_style : String = "#[fg=green]",
|
||||
selected_hint_style : String = "#[selected_hint]",
|
||||
selected_highlight_style : String = "#[selected_highlight]",
|
||||
selected : Bool = false,
|
||||
offset : Tuple(Int32, Int32) | Nil = nil,
|
||||
hint : String = "a",
|
||||
|
|
@ -15,7 +15,7 @@ def setup(
|
|||
)
|
||||
formatter = Fingers::MatchFormatter.new(
|
||||
highlight_style: highlight_style,
|
||||
backdrop_style: "#[bg=black,fg=white]",
|
||||
backdrop_style: "#[backdrop]",
|
||||
hint_style: hint_style,
|
||||
selected_highlight_style: selected_highlight_style,
|
||||
selected_hint_style: selected_hint_style,
|
||||
|
|
@ -31,14 +31,14 @@ describe Fingers::MatchFormatter do
|
|||
context "is set to left" do
|
||||
it "places the hint on the left side" do
|
||||
result = setup(hint_position: "left")
|
||||
result.should eq("#[reset]#[reset]#[fg=yellow,bold]a#[reset]#[fg=yellow]olo#[reset]#[bg=black,fg=white]")
|
||||
result.should eq("#[reset]#[reset]#[hint]a#[reset]#[highlight]olo#[reset]#[backdrop]")
|
||||
end
|
||||
end
|
||||
|
||||
context "is set to right" do
|
||||
it "places the hint on the right side" do
|
||||
result = setup(hint_position: "right")
|
||||
result.should eq("#[reset]#[reset]#[fg=yellow]yol#[reset]#[fg=yellow,bold]a#[reset]#[bg=black,fg=white]")
|
||||
result.should eq("#[reset]#[reset]#[highlight]yol#[reset]#[hint]a#[reset]#[backdrop]")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -46,14 +46,21 @@ describe Fingers::MatchFormatter do
|
|||
context "when a hint is selected" do
|
||||
it "selects the correct format" do
|
||||
result = setup(selected: true)
|
||||
result.should eq("#[reset]#[reset]#[fg=green,bold]a#[reset]#[fg=green]olo#[reset]#[bg=black,fg=white]")
|
||||
result.should eq("#[reset]#[reset]#[selected_hint]a#[reset]#[selected_highlight]olo#[reset]#[backdrop]")
|
||||
end
|
||||
end
|
||||
|
||||
context "when offset is provided" do
|
||||
it "only highlights at specified offset" do
|
||||
result = setup(offset: {1, 5}, highlight: "yoloyoloyolo", hint: "a")
|
||||
result.should eq("#[reset]#[bg=black,fg=white]y#[reset]#[fg=yellow,bold]a#[reset]#[fg=yellow]loyo#[reset]#[bg=black,fg=white]loyolo#[bg=black,fg=white]")
|
||||
result.should eq("#[reset]#[backdrop]y#[reset]#[hint]a#[reset]#[highlight]loyo#[reset]#[backdrop]loyolo#[backdrop]")
|
||||
end
|
||||
end
|
||||
|
||||
context "when offset is at the beginning" do
|
||||
it "only highlights at specified offset" do
|
||||
result = setup(offset: {0, 3}, highlight: "yolo", hint: "a")
|
||||
result.should eq("#[reset]#[reset]#[hint]a#[reset]#[highlight]ol#[reset]#[backdrop]o#[backdrop]")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ module Fingers
|
|||
private getter :hint_style, :highlight_style, :selected_hint_style, :selected_highlight_style, :hint_position, :reset_sequence, :backdrop_style
|
||||
|
||||
private def before_offset(offset, highlight)
|
||||
return "" if offset.nil?
|
||||
return "" if offset.nil? || offset[0] == 0
|
||||
start, _ = offset
|
||||
backdrop_style + highlight[0..(start - 1)]
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue