- Authors::const_iterator it(authors_.begin());
- Authors::const_iterator itend(authors_.end());
-
- for (; it != itend; ++it) {
- if (it->second == a)
- return it->first;
+ bool const valid = a.valid();
+ // If we record an author which equals the current
+ // author, we copy the buffer_id, so that it will
+ // keep the same id in the file.
+ if (valid && !authors_.empty() && a == authors_[0])
+ authors_[0].setBufferId(a.bufferId());
+
+ Authors::const_iterator it = authors_.begin();
+ Authors::const_iterator const beg = it;
+ Authors::const_iterator const end = authors_.end();
+ for (; it != end; ++it) {
+ if (valid && *it == a)
+ return it - beg;
+ if (it->bufferId() == a.bufferId()) {
+ int id = it - beg;
+ if (!it->valid())
+ // we need to handle the case of a valid author being registred
+ // after an invalid one. For instance, because "buffer-reload"
+ // does not clear the buffer's author list.
+ record(id, a);
+ return id;
+ }