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

View File

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

View File

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