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:
Damien Elmes 2012-04-23 06:24:59 +09:00
parent 7295bb829d
commit 2ad2244395

View file

@ -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,7 +241,14 @@ 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"):
tag.replaceWithChildren() # 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()
# turn file:/// links into relative ones # turn file:/// links into relative ones
for tag in doc("img"): for tag in doc("img"):
if tag['src'].lower().startswith("file://"): if tag['src'].lower().startswith("file://"):
@ -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
###################################################################### ######################################################################