Redefine Ctrl+Backspace accelerator

Posted by Ulenspiegel on Sun 25 Jun 2017 07:11 AM — 5 posts, 28,123 views.

#0
Hello!

This brings up a question that was coming up before at least twice in different categories of forum, but I don't think it received any resolution. Reply http://www.gammon.com.au/forum/?id=10818&reply=7#reply7 suggests that, to redefine behavior of Ctrl+Backspace, one can use AcceleratorTo(). Does anybody know how, in the script argument of AcceleratorTo(), delete the last word before cursor? Is there Lua functions for editing the text in input area (I'm looking for 'delete last word' or, for the lack of it, something like 'select previous word' + 'delete selection' functions)?
USA Global Moderator #1
Try

GetCommand, find the last word, SelectCommand (or SetCommandSelection if you prefer), and then PasteCommand
Amended on Sun 25 Jun 2017 08:23 AM by Fiendish
USA #2
nm, SetCommand tries to save us from ourselves.
Amended on Sun 25 Jun 2017 03:33 PM by WillFa
USA Global Moderator #3
WillFa said:

nm, SetCommand tries to save us from ourselves.


lol, yup. PasteCommand claims not to, though.
#4
Everything works well now; thank you all for the help. :)

I think I'll leave that fragment of code here in this thread, in case somebody else will come looking.


function DeleteWordBeforeCursor()
  local sel_end = GetInfo(237)
  if sel_end == 0 then
    local word_end = GetInfo(236) - 1
    if word_end ~= 0 then
      local cmd = GetCommand()
      local word_begin = string.find(string.sub(cmd, 1, word_end), "%S*%s*$")
      if word_begin ~= nil then
        SetCommandSelection(word_begin, word_end)
        PasteCommand("")
      end
    end
  else
    PasteCommand("")
  end
end

-- Redefine Ctrl+Backspace to delete word before caret position.
AcceleratorTo("Ctrl+Backspace", "DeleteWordBeforeCursor()", sendto.script)