mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
81fe7d3180
commit
1ef173bca5
@ -350,8 +350,8 @@ def run_rapydscript_tests():
|
|||||||
setup_fake_protocol, setup_profile
|
setup_fake_protocol, setup_profile
|
||||||
)
|
)
|
||||||
must_use_qt()
|
must_use_qt()
|
||||||
setup_default_profile()
|
|
||||||
setup_fake_protocol()
|
setup_fake_protocol()
|
||||||
|
setup_default_profile()
|
||||||
|
|
||||||
base = base_dir()
|
base = base_dir()
|
||||||
rapydscript_dir = os.path.join(base, 'src', 'pyj')
|
rapydscript_dir = os.path.join(base, 'src', 'pyj')
|
||||||
|
@ -52,6 +52,16 @@ def get_current_time(target): # {{{
|
|||||||
return fstr(target.currentTime or 0)
|
return fstr(target.currentTime or 0)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def id_is_unique(idval): # {{{
|
||||||
|
try:
|
||||||
|
multiples = document.querySelectorAll('[id=' + window.CSS.escape(idval) + ']')
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
if multiples and multiples.length < 2:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
# }}}
|
||||||
|
|
||||||
# Convert point to character offset {{{
|
# Convert point to character offset {{{
|
||||||
def range_has_point(range_, x, y):
|
def range_has_point(range_, x, y):
|
||||||
rects = range_.getClientRects()
|
rects = range_.getClientRects()
|
||||||
@ -239,13 +249,8 @@ def encode(doc, node, offset, tail):
|
|||||||
# Add id assertions for robustness where possible
|
# Add id assertions for robustness where possible
|
||||||
id = node.id
|
id = node.id
|
||||||
idspec = ''
|
idspec = ''
|
||||||
if id:
|
if id and id_is_unique(id):
|
||||||
try:
|
idspec = ('[' + escape_for_cfi(id) + ']')
|
||||||
multiples = document.querySelectorAll('#' + id)
|
|
||||||
except:
|
|
||||||
multiples = None
|
|
||||||
if multiples and multiples.length < 2:
|
|
||||||
idspec = ('[' + escape_for_cfi(id) + ']')
|
|
||||||
cfi = '/' + index + idspec + cfi
|
cfi = '/' + index + idspec + cfi
|
||||||
node = p
|
node = p
|
||||||
|
|
||||||
@ -274,13 +279,8 @@ def node_at_index(nodes, target, index, iter_text_nodes):
|
|||||||
def node_for_path_step(parent, target, assertion):
|
def node_for_path_step(parent, target, assertion):
|
||||||
if assertion:
|
if assertion:
|
||||||
q = document.getElementById(assertion)
|
q = document.getElementById(assertion)
|
||||||
if q:
|
if q and id_is_unique(assertion):
|
||||||
try:
|
return q
|
||||||
multiples = document.querySelectorAll('#' + assertion)
|
|
||||||
except:
|
|
||||||
multiples = None
|
|
||||||
if multiples and multiples.length < 2:
|
|
||||||
return q
|
|
||||||
is_element = target % 2 == 0
|
is_element = target % 2 == 0
|
||||||
target //= 2
|
target //= 2
|
||||||
if is_element and target > 0:
|
if is_element and target > 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user