mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
fix foreground colour issues
- use setFormat() again, as I can't reproduce crashes on any platform anymore, and wrap() didn't allow users to set a colour and then start typing. - work around a qt bug where focus is not restored after native color dialog closes
This commit is contained in:
parent
7295bb829d
commit
2ad2244395
1 changed files with 12 additions and 17 deletions
|
@ -118,17 +118,6 @@ function onFocus(elem) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSel() {
|
|
||||||
sel = document.getSelection();
|
|
||||||
savedSel = sel.getRangeAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreSel() {
|
|
||||||
sel = document.getSelection();
|
|
||||||
sel.removeAllRanges();
|
|
||||||
sel.addRange(savedSel);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDragOver(elem) {
|
function onDragOver(elem) {
|
||||||
elem.focus();
|
elem.focus();
|
||||||
}
|
}
|
||||||
|
@ -252,6 +241,13 @@ def _filterHTML(html):
|
||||||
for tag in doc("span", "Apple-style-span"):
|
for tag in doc("span", "Apple-style-span"):
|
||||||
tag.replaceWithChildren()
|
tag.replaceWithChildren()
|
||||||
for tag in doc("font", "Apple-style-span"):
|
for tag in doc("font", "Apple-style-span"):
|
||||||
|
# strip all but colour attr from implicit font tags
|
||||||
|
if 'color' in dict(tag.attrs):
|
||||||
|
tag.attrs = ((u"color", tag['color']),)
|
||||||
|
# and apple class
|
||||||
|
del tag['class']
|
||||||
|
else:
|
||||||
|
# remove completely
|
||||||
tag.replaceWithChildren()
|
tag.replaceWithChildren()
|
||||||
# turn file:/// links into relative ones
|
# turn file:/// links into relative ones
|
||||||
for tag in doc("img"):
|
for tag in doc("img"):
|
||||||
|
@ -730,13 +726,13 @@ class Editor(object):
|
||||||
|
|
||||||
# use last colour
|
# use last colour
|
||||||
def onForeground(self):
|
def onForeground(self):
|
||||||
self.web.eval("saveSel();")
|
|
||||||
self._wrapWithColour(self.fcolour)
|
self._wrapWithColour(self.fcolour)
|
||||||
|
|
||||||
# choose new colour
|
# choose new colour
|
||||||
def onChangeCol(self):
|
def onChangeCol(self):
|
||||||
self.web.eval("saveSel();")
|
new = QColorDialog.getColor(QColor(self.fcolour), None)
|
||||||
new = QColorDialog.getColor(QColor(self.fcolour), self.widget)
|
# native dialog doesn't refocus us for some reason
|
||||||
|
self.parentWindow.activateWindow()
|
||||||
if new.isValid():
|
if new.isValid():
|
||||||
self.fcolour = new.name()
|
self.fcolour = new.name()
|
||||||
self.onColourChanged()
|
self.onColourChanged()
|
||||||
|
@ -750,8 +746,7 @@ class Editor(object):
|
||||||
self.mw.pm.profile['lastColour'] = self.fcolour
|
self.mw.pm.profile['lastColour'] = self.fcolour
|
||||||
|
|
||||||
def _wrapWithColour(self, colour):
|
def _wrapWithColour(self, colour):
|
||||||
self._eval("restoreSel(); wrap('<font color=\"%s\">', '</font>');"%
|
self._eval("setFormat('forecolor', '%s')" % colour)
|
||||||
colour)
|
|
||||||
|
|
||||||
# Audio/video/images
|
# Audio/video/images
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue