make sure sort field updated when field deleted (#737)
This commit is contained in:
parent
f3f7835032
commit
7957dff33f
@ -250,17 +250,23 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
|||||||
|
|
||||||
def remField(self, m, field):
|
def remField(self, m, field):
|
||||||
self.col.modSchema()
|
self.col.modSchema()
|
||||||
|
# save old sort field
|
||||||
|
sortFldName = m['flds'][m['sortf']]['name']
|
||||||
idx = m['flds'].index(field)
|
idx = m['flds'].index(field)
|
||||||
m['flds'].remove(field)
|
m['flds'].remove(field)
|
||||||
if m['sortf'] >= len(m['flds']):
|
# restore old sort field if possible, or revert to first field
|
||||||
m['sortf'] -= 1
|
m['sortf'] = 0
|
||||||
|
for c, f in enumerate(m['flds']):
|
||||||
|
if f['name'] == sortFldName:
|
||||||
|
m['sortf'] = c
|
||||||
|
break
|
||||||
self._updateFieldOrds(m)
|
self._updateFieldOrds(m)
|
||||||
def delete(fields):
|
def delete(fields):
|
||||||
del fields[idx]
|
del fields[idx]
|
||||||
return fields
|
return fields
|
||||||
self._transformFields(m, delete)
|
self._transformFields(m, delete)
|
||||||
if idx == self.sortIdx(m):
|
if m['flds'][m['sortf']]['name'] != sortFldName:
|
||||||
# need to rebuild
|
# need to rebuild sort field
|
||||||
self.col.updateFieldCache(self.nids(m))
|
self.col.updateFieldCache(self.nids(m))
|
||||||
# saves
|
# saves
|
||||||
self.renameField(m, field, None)
|
self.renameField(m, field, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user