Fix pylint warnings

This commit is contained in:
Artur Shaikhullin 2018-01-05 22:44:07 +06:00
parent 5553e64a75
commit dc8c919c30
3 changed files with 22 additions and 15 deletions

View File

@ -849,14 +849,14 @@ class CommandDispatcher:
s = self._yank_url(what)
what = 'URL' # For printing
elif what == 'selection':
def yank_callback(s):
def _selection_callback(s):
if not self._current_widget().caret.has_selection() or not s:
message.info("Nothing to yank")
return
self._yank_to_target(s, sel, what, keep)
caret = self._current_widget().caret
caret.selection(callback=yank_callback)
caret.selection(callback=_selection_callback)
return
else: # pragma: no cover
raise ValueError("Invalid value {!r} for `what'.".format(what))
@ -1212,7 +1212,7 @@ class CommandDispatcher:
log.procs.debug("Executing {} with args {}, userscript={}".format(
cmd, args, userscript))
if userscript:
def selection_callback(s):
def _selection_callback(s):
try:
self._run_userscript(s, cmd, args, verbose)
except cmdexc.CommandError as e:
@ -1224,7 +1224,7 @@ class CommandDispatcher:
# until it fixed or blocked async call implemented:
# https://github.com/qutebrowser/qutebrowser/issues/3327
caret = self._current_widget().caret
caret.selection(callback=selection_callback)
caret.selection(callback=_selection_callback)
else:
cmd = os.path.expanduser(cmd)
proc = guiprocess.GUIProcess(what='command', verbose=verbose,

View File

@ -203,12 +203,13 @@ class WebEngineCaret(browsertab.AbstractCaret):
@pyqtSlot(usertypes.KeyMode)
def _on_mode_entered(self, mode):
self._tab.run_js_async(
javascript.assemble('caret', 'setInitialCursor', platform.platform()))
javascript.assemble('caret', 'setInitialCursor',
platform.platform()))
@pyqtSlot(usertypes.KeyMode)
def _on_mode_left(self):
self.drop_selection()
self._js_call('toggle')
self._js_call('disableCaret')
def move_to_next_line(self, count=1):
for _ in range(count):

View File

@ -816,15 +816,15 @@ window._qutebrowser.caret = (function() {
*/
CaretBrowsing.setInitialCursor = function(platform) {
CaretBrowsing.isWindows = platform === "Windows";
if (window.getSelection().rangeCount > 0) {
return;
const selectionRange = window.getSelection().toString().length;
if (selectionRange === 0) {
positionCaret();
}
positionCaret();
CaretBrowsing.injectCaretStyles();
CaretBrowsing.toggle();
CaretBrowsing.initiated = true;
CaretBrowsing.selectionEnabled = false;
CaretBrowsing.selectionEnabled = selectionRange > 0;
};
/**
@ -1193,15 +1193,17 @@ window._qutebrowser.caret = (function() {
}, 0);
};
CaretBrowsing.toggle = function() {
CaretBrowsing.toggle = function(value) {
if (CaretBrowsing.forceEnabled) {
CaretBrowsing.recreateCaretElement();
return;
}
CaretBrowsing.isEnabled = !CaretBrowsing.isEnabled;
const obj = {};
obj.enabled = CaretBrowsing.isEnabled;
if (value === undefined) {
CaretBrowsing.isEnabled = !CaretBrowsing.isEnabled;
} else {
CaretBrowsing.isEnabled = value;
}
CaretBrowsing.updateIsCaretVisible();
};
@ -1306,12 +1308,16 @@ window._qutebrowser.caret = (function() {
return;
}
if (!window.getSelection().toString()) {
if (window.getSelection().toString().length === 0) {
positionCaret();
}
CaretBrowsing.toggle();
};
funcs.disableCaret = () => {
CaretBrowsing.toggle(false);
};
funcs.toggle = () => {
CaretBrowsing.toggle();
};