Created
April 11, 2011 14:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------ | |
-- Auto enter insert mode when input field focused on page load -- | |
-- (C) 2011 Mason Larobina <[email protected]> -- | |
------------------------------------------------------------------ | |
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