mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Keep last file positions in last-use ordering
Using a map would sort the elements in alphabetic ordering, which means that when the number of elements is larger than 100, the wrong elements get pruned. This commit uses a list instead. Searching an item needs linear time, but this should not be a problem for a list with less than 100 elements. Fixes bug #10310.
This commit is contained in:
parent
ac106bd720
commit
58d22e0c6e
@ -345,9 +345,10 @@ BufferView::~BufferView()
|
|||||||
// That is to say, if a cursor is in a nested inset, it will be
|
// That is to say, if a cursor is in a nested inset, it will be
|
||||||
// restore to the left of the top level inset.
|
// restore to the left of the top level inset.
|
||||||
LastFilePosSection::FilePos fp;
|
LastFilePosSection::FilePos fp;
|
||||||
|
fp.file = buffer_.fileName();
|
||||||
fp.pit = d->cursor_.bottom().pit();
|
fp.pit = d->cursor_.bottom().pit();
|
||||||
fp.pos = d->cursor_.bottom().pos();
|
fp.pos = d->cursor_.bottom().pos();
|
||||||
theSession().lastFilePos().save(buffer_.fileName(), fp);
|
theSession().lastFilePos().save(fp);
|
||||||
|
|
||||||
if (d->last_inset_)
|
if (d->last_inset_)
|
||||||
d->last_inset_->setMouseHover(this, false);
|
d->last_inset_->setMouseHover(this, false);
|
||||||
|
@ -196,10 +196,10 @@ void LastFilePosSection::read(istream & is)
|
|||||||
getline(itmp, fname);
|
getline(itmp, fname);
|
||||||
if (!FileName::isAbsolute(fname))
|
if (!FileName::isAbsolute(fname))
|
||||||
continue;
|
continue;
|
||||||
FileName const file(fname);
|
filepos.file = FileName(fname);
|
||||||
if (file.exists() && !file.isDirectory()
|
if (filepos.file.exists() && !filepos.file.isDirectory()
|
||||||
&& lastfilepos.size() < num_lastfilepos)
|
&& lastfilepos.size() < num_lastfilepos)
|
||||||
lastfilepos[file] = filepos;
|
lastfilepos.push_back(filepos);
|
||||||
else
|
else
|
||||||
LYXERR(Debug::INIT, "LyX: Warning: Ignore pos of last file: " << fname);
|
LYXERR(Debug::INIT, "LyX: Warning: Ignore pos of last file: " << fname);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -212,26 +212,34 @@ void LastFilePosSection::read(istream & is)
|
|||||||
void LastFilePosSection::write(ostream & os) const
|
void LastFilePosSection::write(ostream & os) const
|
||||||
{
|
{
|
||||||
os << '\n' << sec_lastfilepos << '\n';
|
os << '\n' << sec_lastfilepos << '\n';
|
||||||
for (FilePosMap::const_iterator file = lastfilepos.begin();
|
for (auto const & file_p : lastfilepos)
|
||||||
file != lastfilepos.end(); ++file) {
|
os << file_p.pit << ", " << file_p.pos << ", " << file_p.file << '\n';
|
||||||
os << file->second.pit << ", " << file->second.pos << ", "
|
|
||||||
<< file->first << '\n';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LastFilePosSection::save(FileName const & fname, FilePos const & pos)
|
void LastFilePosSection::save(FilePos const & pos)
|
||||||
{
|
{
|
||||||
lastfilepos[fname] = pos;
|
// Remove element if it was already present. Iterating should
|
||||||
|
// not be a problem since the list is small (<100 elements).
|
||||||
|
for (FilePosList::const_iterator it = lastfilepos.begin();
|
||||||
|
it != lastfilepos.end(); ++it)
|
||||||
|
if (it->file == pos.file) {
|
||||||
|
lastfilepos.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert new element at front.
|
||||||
|
lastfilepos.push_front(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LastFilePosSection::FilePos LastFilePosSection::load(FileName const & fname) const
|
LastFilePosSection::FilePos LastFilePosSection::load(FileName const & fname) const
|
||||||
{
|
{
|
||||||
FilePosMap::const_iterator entry = lastfilepos.find(fname);
|
for (auto & fp : lastfilepos)
|
||||||
|
if (fp.file == fname)
|
||||||
// Has position information, return it.
|
// Has position information, return it.
|
||||||
if (entry != lastfilepos.end())
|
return fp;
|
||||||
return entry->second;
|
|
||||||
// Not found, return the first paragraph
|
// Not found, return the first paragraph
|
||||||
return FilePos();
|
return FilePos();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "support/FileName.h"
|
#include "support/FileName.h"
|
||||||
#include "support/types.h"
|
#include "support/types.h"
|
||||||
|
|
||||||
#include <map>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -148,12 +148,13 @@ public:
|
|||||||
///
|
///
|
||||||
struct FilePos {
|
struct FilePos {
|
||||||
FilePos() : pit(0), pos(0) {}
|
FilePos() : pit(0), pos(0) {}
|
||||||
|
support::FileName file;
|
||||||
pit_type pit;
|
pit_type pit;
|
||||||
pos_type pos;
|
pos_type pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
typedef std::map<support::FileName, FilePos> FilePosMap;
|
typedef std::list<FilePos> FilePosList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
@ -165,13 +166,12 @@ public:
|
|||||||
///
|
///
|
||||||
void write(std::ostream & os) const;
|
void write(std::ostream & os) const;
|
||||||
|
|
||||||
/** add cursor position to the fname entry in the filepos map
|
/** add cursor position to the fname entry in the filepos list
|
||||||
@param fname file entry for which to save position information
|
@param pos file name and position of the cursor when the BufferView is closed.
|
||||||
@param pos position of the cursor when the BufferView is closed.
|
|
||||||
*/
|
*/
|
||||||
void save(support::FileName const & fname, FilePos const & pos);
|
void save(FilePos const & pos);
|
||||||
|
|
||||||
/** load saved cursor position from the fname entry in the filepos map
|
/** load saved cursor position from the fname entry in the filepos list
|
||||||
@param fname file entry for which to load position information
|
@param fname file entry for which to load position information
|
||||||
*/
|
*/
|
||||||
FilePos load(support::FileName const & fname) const;
|
FilePos load(support::FileName const & fname) const;
|
||||||
@ -181,8 +181,8 @@ private:
|
|||||||
unsigned int const num_lastfilepos;
|
unsigned int const num_lastfilepos;
|
||||||
|
|
||||||
|
|
||||||
/// a map of file positions
|
/// a list of file positions
|
||||||
FilePosMap lastfilepos;
|
FilePosList lastfilepos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user