mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 06:07:11 -05:00
save and restore selection when setting colour
This commit is contained in:
parent
79e3984a7a
commit
8de899c3f7
1 changed files with 16 additions and 2 deletions
|
|
@ -43,7 +43,9 @@ body { margin: 5px; }
|
||||||
</style><script>
|
</style><script>
|
||||||
%s
|
%s
|
||||||
|
|
||||||
insertHTMLOK = %s;
|
var insertHTMLOK = %s;
|
||||||
|
var savedSel = null;
|
||||||
|
|
||||||
|
|
||||||
String.prototype.format = function() {
|
String.prototype.format = function() {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
|
@ -116,6 +118,17 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
@ -675,6 +688,7 @@ class Editor(object):
|
||||||
self._updateForegroundButton(recent[-1])
|
self._updateForegroundButton(recent[-1])
|
||||||
|
|
||||||
def onForeground(self):
|
def onForeground(self):
|
||||||
|
self.web.eval("saveSel();")
|
||||||
class ColourPopup(QDialog):
|
class ColourPopup(QDialog):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QDialog.__init__(self, parent, Qt.FramelessWindowHint)
|
QDialog.__init__(self, parent, Qt.FramelessWindowHint)
|
||||||
|
|
@ -752,7 +766,7 @@ class Editor(object):
|
||||||
recent = self.mw.pm.profile['recentColours']
|
recent = self.mw.pm.profile['recentColours']
|
||||||
recent.remove(colour)
|
recent.remove(colour)
|
||||||
recent.append(colour)
|
recent.append(colour)
|
||||||
self._eval("setFormat('forecolor', '%s')" % colour)
|
self._eval("restoreSel(); setFormat('forecolor', '%s')" % colour)
|
||||||
self.colourDiag.close()
|
self.colourDiag.close()
|
||||||
self.colourChanged()
|
self.colourChanged()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue