Skip to content

Instantly share code, notes, and snippets.

@mason-larobina
Created April 11, 2011 14:24
Show Gist options
  • Save mason-larobina/913600 to your computer and use it in GitHub Desktop.
Save mason-larobina/913600 to your computer and use it in GitHub Desktop.
Auto enter insert mode when input field focused on page load in luakit
------------------------------------------------------------------
-- Auto enter insert mode when input field focused on page load --
-- (C) 2011 Mason Larobina <mason.larobina@gmail.com> --
------------------------------------------------------------------
local is_editable = [=[
(function () {
var e = document.activeElement;
// we might get a window object if the main frame was focused
if (!e || !e.tagName) {
return false;
}
var name = e.tagName.toLowerCase();
if (name === "textarea" || name === "select") {
return true;
}
if (name === "input") {
var type = e.type.toLowerCase();
if (type === 'text' || type === 'search' || type === 'password') {
return true;
}
}
return false;
})();
]=]
webview.init_funcs.auto_insert = function (view, w)
view:add_signal("load-status", function (v, status)
if status == "finished" then
if view:eval_js(is_editable) == "true" then
w:set_mode("insert")
end
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment