Merge branch 'artur-shaik-caret_on_selection'

This commit is contained in:
Florian Bruhin 2015-06-20 13:09:32 +02:00
commit 4dd23c530a

View File

@ -460,13 +460,20 @@ class WebView(QWebView):
elif mode == usertypes.KeyMode.caret: elif mode == usertypes.KeyMode.caret:
settings = self.settings() settings = self.settings()
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True) settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True)
self.selection_enabled = False self.selection_enabled = bool(self.page().selectedText())
if self.isVisible(): if self.isVisible():
# Sometimes the caret isn't immediately visible, but unfocusing # Sometimes the caret isn't immediately visible, but unfocusing
# and refocusing it fixes that. # and refocusing it fixes that.
self.clearFocus() self.clearFocus()
self.setFocus(Qt.OtherFocusReason) self.setFocus(Qt.OtherFocusReason)
# Move the caret to the first element in the viewport if there
# isn't any text which is already selected.
#
# Note: We can't use hasSelection() here, as that's always
# true in caret mode.
if not self.page().selectedText():
self.page().currentFrame().evaluateJavaScript( self.page().currentFrame().evaluateJavaScript(
utils.read_file('javascript/position_caret.js')) utils.read_file('javascript/position_caret.js'))