Fix split button

This commit is contained in:
Kovid Goyal 2018-07-27 22:32:55 +05:30
parent 67f3422438
commit 37c277d684
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 7 deletions

View File

@ -6,7 +6,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera
# TODO: # TODO:
# live css # live css
# check that clicking on both internal and external links works # check that clicking on both internal and external links works
# check all buttons in preview panel
import json import json
import textwrap import textwrap
@ -301,10 +300,10 @@ class Bridge(QObject):
except (TypeError, ValueError, OverflowError, AttributeError): except (TypeError, ValueError, OverflowError, AttributeError):
pass pass
@pyqtSlot(native_string_type, native_string_type) @pyqtSlot('QJsonArray', 'QJsonArray')
def request_split(self, loc, totals): def request_split(self, loc, totals):
actions['split-in-preview'].setChecked(False) actions['split-in-preview'].setChecked(False)
loc, totals = json.loads(unicode_type(loc)), json.loads(unicode_type(totals)) loc, totals = [x.toInt() for x in loc], [x.toInt() for x in totals]
if not loc or not totals: if not loc or not totals:
return error_dialog(self.view(), _('Invalid location'), return error_dialog(self.view(), _('Invalid location'),
_('Cannot split on the body tag'), show=True) _('Cannot split on the body tag'), show=True)

View File

@ -28,7 +28,7 @@ def in_table(elem):
def find_containing_block(elem): def find_containing_block(elem):
while elem and elem.getAttribute('data-is-block') != '1': while elem and elem.dataset.isBlock is not '1':
elem = elem.parentNode elem = elem.parentNode
return elem return elem
@ -256,7 +256,7 @@ class PreviewIntegration:
if window is window.top: if window is window.top:
setTimeout(self.connect_channel, 10) setTimeout(self.connect_channel, 10)
document.body.addEventListener('click', self.onclick, True) document.body.addEventListener('click', self.onclick, True)
document.body.appendChild(E.style( document.head.appendChild(E.style(
type='text/css', type='text/css',
'[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }' '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
)) ))
@ -298,7 +298,7 @@ class PreviewIntegration:
def set_split_mode(self, enabled): def set_split_mode(self, enabled):
self.in_split_mode = enabled self.in_split_mode = enabled
document.body.setAttribute('data-in-split-mode', '1' if enabled else '0') document.body.dataset.inSplitMode = '1' if enabled else '0'
if enabled: if enabled:
self.find_blocks() self.find_blocks()
@ -317,7 +317,7 @@ class PreviewIntegration:
parent = parent.parentNode parent = parent.parentNode
loc.reverse() loc.reverse()
totals.reverse() totals.reverse()
self.bridge.request_split(JSON.stringify(loc), JSON.stringify(totals)) self.bridge.request_split(loc, totals)
def connect_channel(self): def connect_channel(self):
self.qwebchannel = new window.QWebChannel(window.qt.webChannelTransport, def(channel): self.qwebchannel = new window.QWebChannel(window.qt.webChannelTransport, def(channel):