Start implementing auto_insert_mode
This commit is contained in:
parent
c2d871a7c3
commit
1c5ae25b68
2
TODO
2
TODO
@ -4,8 +4,6 @@ keyparser foo
|
||||
- Handle keybind to get out of insert mode (e.g. esc)
|
||||
- Switch to normal mode if new page loaded
|
||||
- Add passthrough-keys option to pass through unmapped keys
|
||||
- Add auto-insert-mode to switch to insert mode if editable element is focused
|
||||
after page load
|
||||
- Add more element-selection-detection code (with options?) based on:
|
||||
-> javascript: http://stackoverflow.com/a/2848120/2085149
|
||||
-> microFocusChanged and check active element via:
|
||||
|
@ -171,6 +171,11 @@ DATA = OrderedDict([
|
||||
SettingValue(types.Bool(), "true"),
|
||||
"Whether to switch to insert mode when clicking flash and other "
|
||||
"plugins."),
|
||||
|
||||
('auto_insert_mode',
|
||||
SettingValue(types.Bool(), "true"),
|
||||
"Whether to automatically enter insert mode if an editable element "
|
||||
"is focused after page load."),
|
||||
)),
|
||||
|
||||
('tabbar', sect.KeyValue(
|
||||
|
@ -52,6 +52,14 @@ def leave(mode):
|
||||
manager.leave(mode)
|
||||
|
||||
|
||||
def maybe_leave(mode):
|
||||
"""Convenience method to leave 'mode' without exceptions."""
|
||||
try:
|
||||
manager.leave(mode)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
class ModeManager(QObject):
|
||||
|
||||
"""Manager for keyboard modes.
|
||||
|
@ -85,6 +85,7 @@ class BrowserTab(QWebView):
|
||||
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||
self.page_.linkHovered.connect(self.linkHovered)
|
||||
self.linkClicked.connect(self.on_link_clicked)
|
||||
self.loadFinished.connect(self.on_load_finished)
|
||||
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
||||
|
||||
def _init_neighborlist(self):
|
||||
@ -242,6 +243,21 @@ class BrowserTab(QWebView):
|
||||
self.setFocus()
|
||||
QApplication.postEvent(self, evt)
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def on_load_finished(self, ok):
|
||||
"""Handle insert mode after loading finished."""
|
||||
if config.get('general', 'auto_insert_mode'):
|
||||
frame = self.page_.currentFrame()
|
||||
# FIXME better selector (from hintmanager)
|
||||
elem = frame.findFirstElement('*:focus')
|
||||
logging.debug("focus element: {}".format(not elem.isNull()))
|
||||
if elem.isNull():
|
||||
modemanager.maybe_leave("insert")
|
||||
else:
|
||||
modemanager.enter("insert")
|
||||
else:
|
||||
modemanager.maybe_leave("insert")
|
||||
|
||||
@pyqtSlot(str)
|
||||
def set_force_open_target(self, target):
|
||||
"""Change the forced link target. Setter for _force_open_target.
|
||||
|
Loading…
Reference in New Issue
Block a user