Skip to content

Commit

Permalink
fix immediate hotstrings sending their own last character, such as `:…
Browse files Browse the repository at this point in the history
…*:abc::cde`

until recently, this used to falsely only send `de` instead of `cde`

similar to #51
  • Loading branch information
phil294 committed Jul 29, 2023
1 parent 26f1722 commit df8e013
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/run/display/hotstring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ module Run
other_keysyms.join[...other_size].downcase == @abbrev.downcase
end
end
def trigger(runner, end_char_key_event = nil)
def trigger(runner, trigger_char_key_event)
runner.display.pause do
if @automatic_backspacing
(@abbrev.size + (@immediate ? 0 : 1)).times do
runner.display.x_do.keys "BackSpace", delay: 0
sleep @delay.milliseconds if @delay != -1
end
end
if end_char_key_event
# Same xdotool workaround as in send.cr
end_char_key_up = XDo::LibXDo::Charcodemap.new
end_char_key_up.code = end_char_key_event.keycode
runner.display.x_do.keys_raw [end_char_key_up], pressed: false, delay: 0
end
# Same xdotool workaround as in send.cr.
# Trigger char is either end key or the last key of an immediate hotstring.
# TODO: tests for both cases:
# end key space: `::btw::by the way` without this the first space is missing (test didn;t fail though??)
# no end key: `:*:btw::wy the way` the `w` wasn't typed
end_char_key_up = XDo::LibXDo::Charcodemap.new
end_char_key_up.code = trigger_char_key_event.keycode
runner.display.x_do.keys_raw [end_char_key_up], pressed: false, delay: 0
end

runner.add_thread @cmd.not_nil!, @label, @priority
Expand Down
4 changes: 2 additions & 2 deletions src/run/display/hotstrings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Run
@key_buff_i = 0_u8
if ! prev_candidate.nil?
@runner.set_global_built_in_static_var("A_EndChar", char.to_s)
prev_candidate.trigger(@runner, end_char_key_event: key_event)
prev_candidate.trigger(@runner, key_event)
end
else
@key_buff_i = 0_u8 if @key_buff_i > 29
Expand All @@ -64,7 +64,7 @@ module Run
if match.immediate
@key_buff_i = 0_u8
@runner.set_global_built_in_static_var("A_EndChar", "")
match.trigger(@runner)
match.trigger(@runner, key_event)
else
@candidate = match
end
Expand Down

0 comments on commit df8e013

Please sign in to comment.